Loading…

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 · MT4 · v1.0 · Free

About Multi Timeframe EA Framework

Multi Timeframe EA Framework is an expert advisor (trading robot) for MetaTrader 4 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.ex4, MultiTimeframeFramework.mq4, MultiTimeframeFramework.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Filter timeframePERIOD_H4Higher timeframe used for the trend filter
Filter ma period50Moving average period on the filter timeframe
Trigger timeframePERIOD_M15Lower timeframe used for the entry trigger
Trigger fast period8Fast MA period on the trigger timeframe
Trigger slow period21Slow MA period on the trigger timeframe
Lots0.01Fixed lot size - replace with real sizing
Stop loss pips30Stop loss per trade, in pips
Take profit pips45Take profit per trade, in pips (0 = none)
Magic number20260828Magic number for orders opened by this EA
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per order action before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Multi-Timeframe (MTF) · Trend · Moving Average · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria