Why Timeframe Mastery Matters in MetaTrader
Every trader and developer who uses MetaTrader 4 or 5 interacts with timeframes constantly. Yet most users only scratch the surface — clicking the M15 button or pressing F8 to change the period. Understanding how timeframes work under the hood, how to switch between them efficiently, and how to combine them in multi-timeframe analysis (MTF) can dramatically improve both your manual trading workflow and your Expert Advisor logic.
This guide covers everything from basic chart period navigation to advanced techniques: custom timeframes in MT5, keyboard shortcuts that save clicks, and writing MQL4/MQL5 code that pulls data from higher timeframes inside your EA. By the end, you will navigate timeframes like a pro and avoid the common pitfalls that break MTF EAs.
Prerequisites
- MetaTrader 4 or 5 installed (any build). The guide notes where MT4 and MT5 differ.
- A demo or live trading account connected.
- Basic familiarity with opening charts and the Navigator panel.
- For the MQL section: MetaEditor installed (comes with MT4/MT5) and a willingness to copy-paste small code snippets.
Step-by-Step: Navigate and Customize Timeframes
1. Switching Timeframes on a Chart
The most direct way to change a chart's timeframe is the toolbar button bar. In both MT4 and MT5, you will see buttons labeled M1, M5, M15, M30, H1, H4, D1, W1, MN. Click any to apply that period to the active chart.
Keyboard shortcuts (faster):
- F8 — Opens the Chart Properties window. Under the "Common" tab, you can set the period from a dropdown. This is slower but useful if you need to change multiple settings at once.
- Use the period separator shortcut: In MT4, press Ctrl + F to cycle forward through timeframes. In MT5, Ctrl + F does the same. To go backward, use Ctrl + B (MT4) or Ctrl + Shift + F (MT5).
Pro tip: Memorize the direct hotkeys for common timeframes: F1 (M1), F2 (M5), F3 (M15), F4 (M30), F5 (H1), F6 (H4), F7 (D1), F8 (W1), F9 (MN). These work in both MT4 and MT5. This is the single biggest time-saver for manual traders.
2. Adding a Second Timeframe to the Same Chart (MT5 Only)
MT5 allows you to display multiple timeframes on a single chart window using the "Subwindow" feature. Right-click the chart, select "Template" → "Save Template" first if you want to keep your current indicators. Then go to Charts → Subwindow → New Subwindow. A second chart pane appears below the main one. Drag an indicator or another symbol into it, or change its timeframe independently.
MT4 limitation: MT4 does not support subwindows. You must open separate chart windows for each timeframe and tile them manually (Window → Tile Vertically/Horizontally).
3. Custom Timeframes in MT5
MT5 supports custom timeframes beyond the standard nine. For example, you can create an M2, M3, M6, M10, M20, or H2 chart. Go to Charts → Period → Custom Period. A dialog appears where you enter the number of minutes. Valid values are 2 to 10080 (7 days). The chart will generate using tick data if available, otherwise it uses M1 data to construct the candles.
Important: Custom timeframes are stored as separate chart templates. You cannot use the F-key shortcuts for them. Also, not all brokers provide tick history deep enough to build accurate custom periods — test with your broker's data first.
Multi-Timeframe Analysis in MQL4/MQL5
Writing an EA that checks conditions on a higher timeframe (e.g., H4 trend) while executing trades on a lower timeframe (e.g., M15) is a core skill. The key is to use the iClose(), iOpen(), iHigh(), iLow(), and iMA() functions with the desired ENUM_TIMEFRAMES constant.
MQL4 Example: Check H4 Moving Average on M15 Chart
//+------------------------------------------------------------------+
//| Check if price is above H4 200-period SMA |
//+------------------------------------------------------------------+
bool IsAboveH4MA()
{
double maH4 = iMA(_Symbol, PERIOD_H4, 200, 0, MODE_SMA, PRICE_CLOSE, 0);
double price = iClose(_Symbol, PERIOD_H4, 0); // current H4 close
return (price > maH4);
}
In MQL5, the approach is similar but uses CopyClose() and CopyBuffer() because MQL5 does not have direct iClose() functions. Here is the equivalent:
//+------------------------------------------------------------------+
//| MQL5: Check H4 200 SMA |
//+------------------------------------------------------------------+
bool IsAboveH4MA()
{
double close[];
ArraySetAsSeries(close, true);
CopyClose(_Symbol, PERIOD_H4, 0, 1, close);
double maBuffer[];
ArraySetAsSeries(maBuffer, true);
int handle = iMA(_Symbol, PERIOD_H4, 200, 0, MODE_SMA, PRICE_CLOSE);
CopyBuffer(handle, 0, 0, 1, maBuffer);
IndicatorRelease(handle);
return (close[0] > maBuffer[0]);
}
Critical rule: Always call MTF indicator functions from OnTick() or OnCalculate() only when a new bar forms on the higher timeframe to avoid repainting. Use a static datetime variable to track the last checked bar time:
datetime lastH4Bar = 0;
void OnTick()
{
if(Time(_Symbol, PERIOD_H4, 0) != lastH4Bar)
{
lastH4Bar = Time(_Symbol, PERIOD_H4, 0);
bool filter = IsAboveH4MA();
// use filter in trading logic
}
}
Common MQL Pitfall: Wrong Timeframe Constant
MQL4 uses predefined constants like PERIOD_H1, PERIOD_H4, PERIOD_D1. MQL5 uses the same constants but also allows integer values (e.g., 240 for H4). Using 0 always means the current chart timeframe. If you accidentally pass 0 in a MTF function, you will get data from the current chart, not the intended higher timeframe — a silent bug that breaks your EA. Always double-check the constant.
Tips and Best Practices from Experience
- Use the Period Converter indicator for MT4: MT4 lacks custom timeframes natively. The free "Period Converter" indicator (available on MQL5.com) can create M2, M3, M6, M10, M20, and H2 charts by aggregating M1 data. Install it in
Indicatorsfolder and drag onto an M1 chart. - Save a multi-timeframe workspace as a Profile: After arranging multiple charts with different timeframes, go to File → Profiles → Save As. Name it "MTF Setup". Next time you open MT4/MT5, just load that profile and all charts appear instantly.
- Test MTF EAs in the Strategy Tester with "Every tick" mode: Multi-timeframe logic often relies on bar open times. Using "Every tick" ensures your EA sees every tick and can correctly detect new higher-timeframe bars. "Open prices only" mode may skip ticks and miss bar transitions.
- For MT5 custom timeframes in the Strategy Tester: You cannot backtest a custom period directly. Instead, simulate it by using the nearest standard period and adjusting your logic. For example, if you want M3, test on M1 and count three bars as one "virtual" bar.
Common Mistakes and Troubleshooting
| Mistake | Symptom | Fix |
|---|---|---|
| Using PERIOD_CURRENT in MTF functions | EA only works on one timeframe, ignores higher timeframe filter | Replace PERIOD_CURRENT with the explicit constant (e.g., PERIOD_H4) |
| Not checking for new higher-timeframe bars | EA repaints signals, opens multiple trades on same bar | Use static datetime variable and compare with iTime() |
| MT4 custom timeframe not showing | No chart appears or blank window | Install Period Converter indicator and apply to M1 chart; ensure M1 tick data is present |
| MT5 Strategy Tester with custom timeframe | Custom period not available in tester dropdown | Use a standard period and adjust EA logic to simulate the custom timeframe |
Summary / Recap and Next Steps
You now know how to navigate MetaTrader timeframes using toolbar buttons, keyboard shortcuts (F1-F9), and custom periods in MT5. You can set up multi-timeframe workspaces with profiles, and you have the MQL4/MQL5 code patterns to build MTF filters into your EAs. The key takeaways:
- Memorize the F-key shortcuts for instant timeframe switching.
- Use profiles to save your multi-chart layouts.
- In MQL, always use explicit timeframe constants and guard against repainting with bar-time checks.
- Test MTF EAs in "Every tick" mode.
Next step: Try building a simple EA that only takes long trades when the H1 50 EMA is rising. Use the code snippets above as a starting point. Then experiment with adding a second timeframe filter (e.g., D1 trend direction). This is the foundation of robust multi-timeframe algorithmic trading.
Frequently Asked Questions
Can I use custom timeframes like M2 or H2 in MT4?
Not natively. MT4 only supports the nine standard periods. You can use a free "Period Converter" indicator from the MQL5 community that runs on an M1 chart and generates custom timeframe data as a separate chart.
How do I prevent my MTF EA from repainting when checking a higher timeframe?
Store the last processed bar time of the higher timeframe in a static variable. Compare it with the current bar time using iTime() (MQL4) or CopyTime() (MQL5). Only update the MTF condition when the bar time changes.
Why does my MT5 custom timeframe chart show no data?
Custom timeframes require tick history. If your broker does not provide deep tick data, the chart may be empty. Try downloading M1 data first (Tools → History Center → select symbol → M1 → Download). Then switch to the custom period.




