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 · MT5 · v1.0 · Free
About Multi Timeframe Overlay Portfolio
Multi Timeframe Overlay Portfolio is an expert advisor (trading robot) for MetaTrader 5 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.ex5, MtfOverlayPortfolio.mq5, MtfOverlayPortfolio.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 |
|---|---|---|
| Timeframe list | M15,H1,H4,D1 | Comma-separated timeframes voting in this portfolio |
| Fast ma period | 10 | Fast MA period, applied identically on every voting timeframe |
| Slow ma period | 30 | Slow MA period, applied identically on every voting timeframe |
| Ma method | MODE_EMA | MA method used by both the fast and slow line |
| Lots per vote | 0.01 | Lot size contributed by each timeframe currently voting a direction |
| Magic number | 20273001 | Magic number identifying this portfolio's own position |
| Slippage points | 50 | Slippage allowance, in points |
| Dry run | false | true = log intended actions only, never trades |
| 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: Hedging · Multi-Timeframe (MTF) · Moving Average · MT5 Expert Advisor · MQL5 Source Code