Triple Timeframe Alignment System
The classic three-timeframe agreement idea is simple to state and easy to implement wrong: read a fast/slow moving-average relationship on three timeframes, and only trade when all three agree. The naive version breaks by reading shift 0 - the currently-forming bar - on the higher timeframes, which repaints. A still-forming H4 bar's close keeps changing as the chart's own M15 bars close underneath it, so a signal built on that value can flicker in and out of existence within the same H4 candle, and a backtest run on repainted values will show trades that could never actually have fired live. This implementation reads every one of the three timeframes - including the chart's own - at explicit shift 1, the last fully closed bar of that series, with no exceptions. A trade is only evaluated once, on the bar the chart timeframe itself closes, so an intrabar wobble in a higher timeframe's still-forming bar can never retroactively change a decision that has already been made. Trend on each timeframe is judged the same simple way: a fast EMA above a slow EMA is bullish, below is bearish. All three bullish opens a long, all three bearish opens a short. Losing agreement while a position is open closes it - this system trades the agreement itself, not a fixed holding period. Notes and limitations Only one position is held at a time and only on the chart's own symbol - this is a single-instrument system, not a portfolio scanner. The trend filter is a plain EMA cross on each timeframe, not a more sophisticated regime classifier; it will whipsaw during ranging conditions like any moving-average system, particularly if the two higher timeframes are close together in duration. Alignment loss closes the position at market on the next tick after the losing bar closes, not intrabar, consistent with the same closed-bar-only evaluation used for entries.
Expert advisor · MT5 · v1.0 · Free
About Triple Timeframe Alignment System
Triple Timeframe Alignment System is an expert advisor (trading robot) for MetaTrader 5 based on Moving Average and ATR. It can size trades from your balance and risk percent. It has 14 settings, such as Fast period, Slow period and Mid tf. MQL source code included.
Files in the download: TripleAlignmentSystem.ex5, TripleAlignmentSystem.mq5, TripleAlignmentSystem.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 |
|---|---|---|
| Fast period | 8 | Fast EMA period, applied identically on all three timeframes |
| Slow period | 21 | Slow EMA period, applied identically on all three timeframes |
| Mid tf | PERIOD_H1 | Middle confirming timeframe |
| High tf | PERIOD_H4 | Highest confirming timeframe |
| Atr mult sl | 2.0 | Stop loss distance, multiples of chart-timeframe ATR |
| Atr mult tp | 3.0 | Take profit distance, multiples of chart-timeframe ATR |
| Atr period | 14 | ATR period used for the stop/target distance |
| Use risk sizing | true | Size by percent risk to the stop instead of a fixed lot |
| Risk percent | 1.0 | Percent of equity risked per trade, when risk sizing is on |
| Fixed lots | 0.10 | Lot size when risk sizing is off, or as a sizing fallback |
| Magic number | 33101 | Magic number for orders opened by this EA |
| Slippage pips | 3 | Slippage tolerance, in pips |
| Max retries | 5 | Attempts per trade 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: Trend · Risk & Lot Size · Moving Average · ATR · MT5 Expert Advisor · MQL5 Source Code