I'll create an MQL4 indicator that identifies potential reversal points using multiple confirmation signals. This indicator will combine price action patterns with momentum analysis.
//+------------------------------------------------------------------+
//| ReversalSpotter.mq4 |
//| Reversal Detection |
//| Multi-Signal Approach |
//+------------------------------------------------------------------+
#property copyright "Reversal Spotter"
#property link ""
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 Yellow
#property indicator_color4 Yellow
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 1
#property indicator_width4 1
// Input parameters
input int RSI_Period = 14; // RSI Period
input double RSI_Overbought = 70; // RSI Overbought Level
input double RSI_Oversold = 30; // RSI Oversold Level
input int Lookback_Bars = 10; // Bars to check for swing highs/lows
input double Min_PinBar_Ratio = 0.65; // Minimum pin bar wick ratio
input bool Show_Alerts = true; // Enable alerts
input bool Use_Divergence = true; // Check for RSI divergence
input int MA_Period = 20; // Moving Average Period
// Indicator buffers
double BullishSignal[];
double BearishSignal[];
double ResistanceLine[];
double SupportLine[];
// Global variables
datetime lastAlertTime = 0;
double lastHigh = 0;
double lastLow = 0;
int lastHighBar = 0;
int lastLowBar = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Set indicator buffers
SetIndexBuffer(0, BullishSignal);
SetIndexBuffer(1, BearishSignal);
SetIndexBuffer(2, ResistanceLine);
SetIndexBuffer(3, SupportLine);
// Set indicator styles
SetIndexStyle(0, DRAW_ARROW);
SetIndexArrow(0, 233); // Up arrow
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 234); // Down arrow
SetIndexStyle(2, DRAW_LINE, STYLE_DOT);
SetIndexStyle(3, DRAW_LINE, STYLE_DOT);
// Set empty values
SetIndexEmptyValue(0, 0.0);
SetIndexEmptyValue(1, 0.0);
SetIndexEmptyValue(2, 0.0);
SetIndexEmptyValue(3, 0.0);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Check if bar is a pin bar |
//+------------------------------------------------------------------+
bool IsPinBar(int bar, bool bullish)
{
double open = Open[bar];
double high = High[bar];
double low = Low[bar];
double close = Close[bar];
double body = MathAbs(close - open);
double range = high - low;
if(range == 0) return false;
if(bullish)
{
double lowerWick = open < close ? open - low : close - low;
return (lowerWick / range >= Min_PinBar_Ratio && body / range <= (1 - Min_PinBar_Ratio));
}
else
{
double upperWick = open > close ? high - open : high - close;
return (upperWick / range >= Min_PinBar_Ratio && body / range <= (1 - Min_PinBar_Ratio));
}
}
//+------------------------------------------------------------------+
//| Check if bar is at swing high |
//+------------------------------------------------------------------+
bool IsSwingHigh(int bar)
{
if(bar + Lookback_Bars >= Bars || bar - Lookback_Bars < 0) return false;
double highPrice = High[bar];
for(int i = 1; i <= Lookback_Bars; i++)
{
if(High[bar + i] >= highPrice || High[bar - i] >= highPrice)
return false;
}
return true;
}
//+------------------------------------------------------------------+
//| Check if bar is at swing low |
//+------------------------------------------------------------------+
bool IsSwingLow(int bar)
{
if(bar + Lookback_Bars >= Bars || bar - Lookback_Bars < 0) return false;
double lowPrice = Low[bar];
for(int i = 1; i <= Lookback_Bars; i++)
{
if(Low[bar + i] <= lowPrice || Low[bar - i] <= lowPrice)
return false;
}
return true;
}
//+------------------------------------------------------------------+
//| Check for RSI divergence |
//+------------------------------------------------------------------+
bool CheckDivergence(int bar, bool bullish)
{
if(!Use_Divergence || bar >= Bars - 50) return false;
double rsi1 = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, bar);
if(bullish) // Bullish divergence
{
// Find previous swing low
for(int i = bar + 5; i < bar + 50 && i < Bars; i++)
{
if(IsSwingLow(i))
{
double rsi2 = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i);
if(Low[bar] < Low[i] && rsi1 > rsi2)
return true;
break;
}
}
}
else // Bearish divergence
{
// Find previous swing high
for(int i = bar + 5; i < bar + 50 && i < Bars; i++)
{
if(IsSwingHigh(i))
{
double rsi2 = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i);
if(High[bar] > High[i] && rsi1 < rsi2)
return true;
break;
}
}
}
return false;
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
int limit = rates_total - prev_calculated;
if(prev_calculated > 0) limit++;
for(int i = MathMin(limit, rates_total - Lookback_Bars - 1); i >= 0; i--)
{
BullishSignal[i] = 0;
BearishSignal[i] = 0;
// Get indicators
double rsi = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i);
double ma = iMA(NULL, 0, MA_Period, 0, MODE_SMA, PRICE_CLOSE, i);
// Check for bullish reversal
bool bullishPinBar = IsPinBar(i, true);
bool atSwingLow = IsSwingLow(i);
bool rsiOversold = rsi < RSI_Oversold;
bool bullishDiv = CheckDivergence(i, true);
bool priceAboveMA = Close[i] > ma;
int bullishScore = 0;
if(bullishPinBar) bullishScore++;
if(atSwingLow) bullishScore++;
if(rsiOversold) bullishScore++;
if(bullishDiv) bullishScore += 2;
if(i > 0 && Close[i] > Close[i+1]) bullishScore++;
// Check for bearish reversal
bool bearishPinBar = IsPinBar(i, false);
bool atSwingHigh = IsSwingHigh(i);
bool rsiOverbought = rsi > RSI_Overbought;
bool bearishDiv = CheckDivergence(i, false);
bool priceBelowMA = Close[i] < ma;
int bearishScore = 0;
if(bearishPinBar) bearishScore++;
if(atSwingHigh) bearishScore++;
if(rsiOverbought) bearishScore++;
if(bearishDiv) bearishScore += 2;
if(i > 0 && Close[i] < Close[i+1]) bearishScore++;
// Signal generation (require multiple confirmations)
if(bullishScore >= 3)
{
BullishSignal[i] = Low[i] - (High[i] - Low[i]) * 0.5;
if(Show_Alerts && i == 0 && Time[0] != lastAlertTime)
{
Alert("Bullish Reversal Signal - ", Symbol(), " ", Period());
lastAlertTime = Time[0];
}
}
if(bearishScore >= 3)
{
BearishSignal[i] = High[i] + (High[i] - Low[i]) * 0.5;
if(Show_Alerts && i == 0 && Time[0] != lastAlertTime)
{
Alert("Bearish Reversal Signal - ", Symbol(), " ", Period());
lastAlertTime = Time[0];
}
}
// Update support/resistance lines
if(atSwingHigh)
{
lastHigh = High[i];
lastHighBar = i;
}
if(atSwingLow)
{
lastLow = Low[i];
lastLowBar = i;
}
// Draw support/resistance lines
if(lastHigh > 0 && i <= lastHighBar)
ResistanceLine[i] = lastHigh;
else
ResistanceLine[i] = 0;
if(lastLow > 0 && i <= lastLowBar)
SupportLine[i] = lastLow;
else
SupportLine[i] = 0;
}
return(rates_total);
}
This reversal detection indicator combines several technical analysis methods:
Key Features:
-
Pin Bar Detection - Identifies candlestick patterns with long wicks that often signal reversals
-
Swing High/Low Detection - Finds local extremes where price reversals commonly occur
-
RSI Analysis - Monitors overbought/oversold conditions and divergences
-
Multi-Confirmation System - Requires multiple signals to align before generating an alert
-
Support/Resistance Lines - Displays recent swing levels as dotted lines
Signal Generation:
- Green up arrows indicate potential bullish reversals
- Red down arrows indicate potential bearish reversals
- Signals appear when 3 or more confirmation criteria are met
Customizable Parameters:
- RSI settings and overbought/oversold levels
- Pin bar sensitivity
- Lookback period for swing detection
- Moving average period for trend context
- Alert functionality
The indicator uses a scoring system to reduce false signals - the more confirmations present, the stronger the reversal signal. You can adjust the parameters based on your trading style and the timeframe you're using.