MT5 Dual-Timeframe RSI: Confirmed Higher-Timeframe Context Without Lookahead
Advanced Trading Tutorial | Full source and original research diagram
Why this study matters
A common multi-timeframe mistake is to use an unfinished H1 RSI value as though it were fixed when generating signals on M15. Because RSI varies until the H1 candle closes, a chart can appear to have a signal historically that was not available at the decision time. This example explicitly maps each M15 bar timestamp to its containing H1 candle, then reads the previous H1 bar.
Signal contract and exact mathematics
The local RSI(14) must cross up through 50 between two completed bars, while the immediately preceding completed H1 RSI(14) must exceed 55. Short signals require a cross below 50 and H1 RSI below 45. A cross itself uses RSI[i+1] and RSI[i]; no forming chart bar at index 0 is eligible. Both indicators are native iRSI handles, and CopyBuffer retrieves their actual values.
A reproducible, hypothetical example
Imagine the 10:15 M15 candle completes with RSI moving from 48.2 to 52.4. The H1 candle starting 10:00 is still incomplete, so the contextual H1 observation is the 09:00 candle, which completed at 10:00. If its confirmed RSI is 58.6, the long arrow qualifies. If its confirmed RSI is 53.1, no arrow qualifies. The bar timestamps, not the current wall-clock RSI, determine valid historical context.

Why index alignment prevents future information
iBarShift maps each lower-timeframe candle to the containing higher-timeframe interval. Adding one to the higher-timeframe shift intentionally selects the preceding, closed H1 bar. This approach also handles old chart history: a historical M15 signal will never borrow an H1 value from a subsequent candle. Missing context and CopyBuffer failures deliberately suppress output rather than fabricate values.
Parameter sensitivity and execution limitations
The default 55/45 H1 gate requires stronger momentum than a simple 50 boundary. Changing these gates to 60/40 should make signals less frequent and potentially later; changing to 52/48 permits more choppy crossover conditions. Increasing local RSI length slows transitions, while shorter periods react more quickly to noise. Signals are arrows, not entries. Next-bar fill, spread, slippage and trading costs require separate research.
Install and validate
Save the source in MQL5/Indicators, compile in MetaEditor and attach to a chart with sufficient M15 and H1 history. For at least ten plotted arrows, record the M15 close, RSI crossover and timestamp of the preceding H1 candle. Compare live bar completion with historical refreshes, weekends and gaps. Check all symbol/session assumptions. This code has not been compiled in a real terminal and must be reviewed before use.
Complete MQL5 indicator source
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrLimeGreen
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrTomato
input int LocalPeriod=14;
input ENUM_TIMEFRAMES HigherTF=PERIOD_H1;
input int HigherPeriod=14;
input double LongGate=55.0;
input double ShortGate=45.0;
double Buy[],Sell[];
int hLocal=INVALID_HANDLE,hHigher=INVALID_HANDLE;
int OnInit()
{
SetIndexBuffer(0,Buy,INDICATOR_DATA);
SetIndexBuffer(1,Sell,INDICATOR_DATA);
ArraySetAsSeries(Buy,true); ArraySetAsSeries(Sell,true);
PlotIndexSetInteger(0,PLOT_ARROW,233);
PlotIndexSetInteger(1,PLOT_ARROW,234);
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
hLocal=iRSI(_Symbol,_Period,LocalPeriod,PRICE_CLOSE);
hHigher=iRSI(_Symbol,HigherTF,HigherPeriod,PRICE_CLOSE);
return(hLocal==INVALID_HANDLE||hHigher==INVALID_HANDLE)?INIT_FAILED:INIT_SUCCEEDED;
}
void OnDeinit(const int reason)
{
if(hLocal!=INVALID_HANDLE) IndicatorRelease(hLocal);
if(hHigher!=INVALID_HANDLE) IndicatorRelease(hHigher);
}
int OnCalculate(const int total,const int prev,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[])
{
if(total<LocalPeriod+4) return 0;
ArraySetAsSeries(time,true); ArraySetAsSeries(high,true);
ArraySetAsSeries(low,true);
double local[],higher[];
ArraySetAsSeries(local,true); ArraySetAsSeries(higher,true);
int count=Bars(_Symbol,HigherTF);
if(count<HigherPeriod+3) return prev;
if(CopyBuffer(hLocal,0,0,total,local)!=total) return prev;
if(CopyBuffer(hHigher,0,0,count,higher)!=count) return prev;
Buy[0]=EMPTY_VALUE;Sell[0]=EMPTY_VALUE;
int last=(prev==0)?total-2:MathMin(total-2,total-prev+2);
for(int i=last;i>=1;i--)
{
Buy[i]=EMPTY_VALUE;Sell[i]=EMPTY_VALUE;
int j=iBarShift(_Symbol,HigherTF,time[i],false);
if(j<0||j+1>=count) continue;
double context=higher[j+1]; // previous completed HTF candle
if(local[i]==EMPTY_VALUE||local[i+1]==EMPTY_VALUE) continue;
if(local[i+1]<=50&&local[i]>50&&context>LongGate)
Buy[i]=low[i]-80*_Point;
if(local[i+1]>=50&&local[i]<50&&context<ShortGate)
Sell[i]=high[i]+80*_Point;
}
return total;
}
Interested in modifying this free indicator for your own workflow? Our Custom Trading Software Development Services can help discuss custom requirements.