Multi Timeframe EA Framework
Combining two timeframes sounds simple - read a higher-timeframe indicator, then look for an entry on a lower one - but the naive version calls the higher-timeframe indicator on every tick of the lower timeframe. Since a not-yet-closed bar's value can still change, that means the "filter" can flip its opinion mid-bar, sometimes after a trigger has already fired on the old reading, silently repainting a decision the EA already acted on. This framework exists to make the fix mechanical rather than something to remember: the filter is only ever recomputed when iTime(symbol, InpFilterTimeframe, 0) reports a new bar on its own timeframe, cached, and reused for every trigger check until the next filter bar closes. The filter and trigger are both intentionally plain moving averages - close-versus-EMA for the filter, a fast/slow EMA crossover for the trigger - because the point of this framework is the multi-timeframe bar handling, not the signal itself. Every indicator call passes its timeframe explicitly rather than relying on Period(), so the EA behaves identically regardless of which chart period it happens to be attached to. InpFilterTimeframe is validated in OnInit() to be greater than or equal to InpTriggerTimeframe, since a filter timeframe shorter than the trigger is not actually a filter. Notes and limitations - The filter bias is cached and only recomputed on a new filter- timeframe bar; a trigger signal on a stale filter bias one tick before the filter rolls is expected behaviour, not a bug. - One position at a time, on the trigger timeframe's bar close only. - Both signals have no claimed edge; they exist only to prove the timeframe handling works correctly end to end. - Requires AutoTrading enabled and IsTradeAllowed() true; if trading is disabled the EA logs it and places nothing.
Expert advisor · MT5 · v1.0 · Free
About Multi Timeframe EA Framework
Multi Timeframe EA Framework is an expert advisor (trading robot) for MetaTrader 5 based on Moving Average. It has 12 settings, such as Filter timeframe, Filter ma period and Trigger timeframe. MQL source code included.
Files in the download: MultiTimeframeFramework.ex5, MultiTimeframeFramework.mq5, MultiTimeframeFramework.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Filter timeframe | PERIOD_H4 | Higher timeframe used for the trend filter |
| Filter ma period | 50 | Moving average period on the filter timeframe |
| Trigger timeframe | PERIOD_M15 | Lower timeframe used for the entry trigger |
| Trigger fast period | 8 | Fast MA period on the trigger timeframe |
| Trigger slow period | 21 | Slow MA period on the trigger timeframe |
| Lots | 0.01 | Fixed lot size - replace with real sizing |
| Stop loss pips | 30 | Stop loss per trade, in pips |
| Take profit pips | 45 | Take profit per trade, in pips (0 = none) |
| Magic number | 20260828 | Magic number for orders opened by this EA |
| Slippage pips | 3 | Slippage tolerance, in pips |
| Max retries | 5 | Attempts per order action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Multi-Timeframe (MTF) · Trend · Moving Average · MT5 Expert Advisor · MQL5 Source Code