Loading…

Multi Timeframe Overlay Portfolio

A naive way to combine several timeframes is to run one EA instance (or one internal sub-strategy) per timeframe, each opening its own ticket. The moment two timeframes disagree, that approach pays spread and commission holding both a position and its own immediate opposite on the same symbol at the same time, which is pure cost with no offsetting benefit on an MQL4 hedging account. This EA instead treats every configured timeframe as one vote. On each tick it evaluates a fast/slow moving-average cross independently on every timeframe in InpTimeframeList, counts how many vote long versus short, and sums the net vote count into one target lot size (net votes times InpLotsPerVote). It then reconciles a single ticket, held under this EA's own magic number, against that target: no ticket and a non-zero target opens one; an existing ticket whose direction or size no longer matches the target is closed and reopened at the new target in one step. At no point does more than one ticket exist for this symbol under this EA's magic number. Because MQL4's ENUM_TIMEFRAMES values are not duration-ordinal (unlike a plain minute count), every timeframe compared or iterated in this EA is carried as a real ENUM_TIMEFRAMES value from the moment InpTimeframeList is parsed, never demoted to a bare int. Notes and limitations - A timeframe with fewer than InpSlowMaPeriod + 2 bars loaded abstains from voting that pass rather than guessing; this can leave it silently out of the vote total right after attaching to an instrument with a short history. - Ties (fast MA within one point of the slow MA) count as an abstention for that timeframe, not a forced long or short. - Resizing on a direction that has not changed is done by closing and reopening the ticket, since MQL4 has no partial-size modify for an open market order's volume; this means a size-only change still pays one round of spread. - No stop-loss or take-profit is placed by this EA - it is a signal- netting layer only, not a full risk-managed system on its own. - Trades only the chart's own symbol; running the same idea on several symbols means attaching one instance per chart, each with its own magic number.

Expert advisor · MT4 · v1.0 · Free

About Multi Timeframe Overlay Portfolio

Multi Timeframe Overlay Portfolio is an expert advisor (trading robot) for MetaTrader 4 based on Moving Average. It has 10 settings, such as Timeframe list, Fast ma period and Slow ma period. MQL source code included.

Files in the download: MtfOverlayPortfolio.ex4, MtfOverlayPortfolio.mq4, MtfOverlayPortfolio.txt.

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

Settings

SettingDefaultWhat it does
Timeframe listM15,H1,H4,D1Comma-separated timeframes voting in this portfolio
Fast ma period10Fast MA period, applied identically on every voting timeframe
Slow ma period30Slow MA period, applied identically on every voting timeframe
Ma methodMODE_EMAMA method used by both the fast and slow line
Lots per vote0.01Lot size contributed by each timeframe currently voting a direction
Magic number20273001Magic number identifying this portfolio's own position
Slippage pips5Slippage allowance, in pips
Dry runfalsetrue = log intended actions only, never trades
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: Hedging · Multi-Timeframe (MTF) · Moving Average · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria