Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Building smart trading tools in MetaTrader 4 (MT4) often comes down to one key idea: get confirmation from more than one timeframe before making a decision. That’s exactly what multi timeframe confirmation in mql4 indicator logic is all about. When you combine signals from higher and lower timeframes, you can often avoid bad trades and focus on higher-quality setups.
In this guide, we’ll walk through the concepts, the MQL4 functions you need, the logic design, and a practical example. You don’t need to be a pro programmer to follow along—just basic MQL4 knowledge and some patience.
Multi timeframe confirmation means you check price action or indicator signals on more than one timeframe before you trade. For example:
It’s like zooming in and out on the same chart. The higher timeframe shows the “big picture,” while the lower timeframe shows the details.
If you rely on a single timeframe, you may:
When your indicator includes multi timeframe confirmation:
On MT4, this is especially powerful because you can program your logic once and use it on any symbol or timeframe.
MT4 stores price data as candles (also called bars). Each bar has:
In MQL4, these are usually accessed through arrays like Time[], Open[], High[], Low[], Close[]. The index 0 is the current forming bar, 1 is the last closed bar, and so on.
For higher or lower timeframes, you use special functions like iTime, iOpen, etc., to get the data for that other timeframe.
Custom indicators in MQL4 use indicator buffers to draw values on the chart:
OnCalculate or start function, you fill these buffers based on your logic.Multi timeframe logic fits right into this structure. For each bar of the current chart, you ask: “What’s happening on the higher timeframe at this moment?” Then, you decide what to draw.
To work with other timeframes in MQL4, you’ll often use functions like:
iTime(symbol, timeframe, index)iOpen(symbol, timeframe, index)iHigh(symbol, timeframe, index)iLow(symbol, timeframe, index)iClose(symbol, timeframe, index)iVolume(symbol, timeframe, index)Here:
symbol is usually NULL (meaning current symbol)timeframe could be PERIOD_M5, PERIOD_H1, etc.index is the bar index on that timeframe (0, 1, 2…)These functions let you read higher timeframe bars from inside your indicator that runs on a lower timeframe chart.
Sometimes, you don’t want to code everything from scratch. With iCustom, you can:
Example idea:
iCustomThis is a flexible way to build layered confirmation logic.
A solid design usually starts with top-down analysis:
Common combinations:
You want the higher timeframe to answer: “Should I look for buys or sells?” The lower timeframe answers: “Is now a good moment to enter?”
Imagine this:
Rules:
Your indicator can show:
Let’s break down how you might code such logic.
You’ll typically define:
This makes your indicator flexible and reusable.
For each bar on the current chart, you need to know which bar on the higher timeframe matches it. You can:
iTime with the higher timeframeiTime is less than or equal to the current bar timeiClose, iMA, or iCustom values from that indexTo avoid errors:
iTime doesn’t return 0 or an invalid timeBecause higher timeframe bars cover more time, several lower timeframe bars will map to the same higher timeframe bar. That’s okay. You just:
This keeps your logic consistent and avoids repainting.
For each lower timeframe bar:
This is the heart of multi timeframe confirmation in an indicator.
“Repainting” means signals change after the fact, making backtests look perfect but real trading terrible. Common causes:
index 0) instead of closed bars (index 1)To reduce repainting:
Multi timeframe indicators can be heavy because they:
To optimize:
Efficient code means smoother charts and fewer platform slowdowns.
Let’s describe a simple indicator:
Rules:
The indicator:
Here’s the logic in simple pseudo-code style (not full code, but close enough to understand):
// Inputs
input ENUM_TIMEFRAMES HigherTF = PERIOD_H1;
input int FastMAPeriod = 10;
input int SlowMAPeriod = 50;
// Buffers for arrows
double BuyArrowBuffer[];
double SellArrowBuffer[];
int OnCalculate(...)
{
// Loop through bars
for(int i = Bars - 1; i >= 1; i--)
{
datetime currentTime = Time[i];
// Get matching higher timeframe bar index
int htIndex = iBarShift(NULL, HigherTF, currentTime, true);
if(htIndex < 0) continue;
// Get higher timeframe trend bias
double htClose = iClose(NULL, HigherTF, htIndex);
double htMA = iMA(NULL, HigherTF, SlowMAPeriod, 0, MODE_EMA, PRICE_CLOSE, htIndex);
bool bullishBias = htClose > htMA;
bool bearishBias = htClose < htMA;
// Get lower timeframe moving averages
double fastMA = iMA(NULL, 0, FastMAPeriod, 0, MODE_EMA, PRICE_CLOSE, i);
double fastPrev = iMA(NULL, 0, FastMAPeriod, 0, MODE_EMA, PRICE_CLOSE, i+1);
double closeNow = Close[i];
double closePrev= Close[i+1];
// Reset arrow buffers
BuyArrowBuffer[i] = EMPTY_VALUE;
SellArrowBuffer[i] = EMPTY_VALUE;
// Buy condition: cross up + bullish bias
if(closePrev < fastPrev && closeNow > fastMA && bullishBias)
BuyArrowBuffer[i] = Low[i] - Point*10;
// Sell condition: cross down + bearish bias
if(closePrev > fastPrev && closeNow < fastMA && bearishBias)
SellArrowBuffer[i] = High[i] + Point*10;
}
return(rates_total);
}
This indicator shows how to combine a higher timeframe trend filter with lower timeframe entries in a structured way.
To test your indicator properly:
Remember: backtests can’t predict the future, but they help you catch logical errors and repainting problems.
Visual debug tips:
Comment() to print real-time values while you watch the chartThese small steps make it much easier to see whether multi timeframe confirmation is working as intended.
To keep your indicator clean and safe:
iBarShift and other index functions return valid indexesGood code is easier to update when you change your strategy later.
Once your logic is solid, you can add:
For extra learning and reference, you can also check the official MQL4 documentation on the MetaQuotes website for details about every function and indicator type.
1. Do I need to be an advanced programmer to use multi timeframe confirmation?
No. Basic MQL4 knowledge is enough if you move slowly and test often. Start with simple filters, such as a higher timeframe moving average, before building complex logic.
2. Can I mix more than two timeframes in one indicator?
Yes. You can combine three or more timeframes, like D1 + H4 + H1. But keep in mind that more filters usually mean fewer signals, so you must balance quality and frequency.
3. Why does my indicator behave differently in backtest and live trading?
This often happens when logic uses open bars or unfinished higher timeframe candles. Always use closed bars for confirmation and check your index handling carefully.
4. Will multi timeframe confirmation remove all losing trades?
No system can do that. Multi timeframe logic can reduce false signals and improve average trade quality, but losses will still occur. Risk management and position sizing remain crucial.
5. Is it better to confirm with trend indicators or oscillators?
Both can work. Many traders use trend tools (like moving averages) on higher timeframes and oscillators (like RSI or stochastic) on lower timeframes for fine-tuned entries.
6. Can I use multi timeframe confirmation in Expert Advisors as well as indicators?
Absolutely. The same functions (iTime, iClose, iMA, iCustom, etc.) are available in Expert Advisors. You can use them to build automated trading systems that respect multi timeframe confirmation rules.
You’ve now seen how multi timeframe confirmation in mql4 indicator logic can turn simple indicators into smarter decision tools. By combining higher timeframe trend filters with lower timeframe entry signals, you:
The next step is to take these ideas and start experimenting in your own MT4 environment. Begin with a simple moving average filter, test it on a demo account, and refine your code as you go.
If you want a deeper technical reference on every function mentioned here, you can explore the official MQL4 documentation on the MetaQuotes site, which covers the full function list and examples in detail.