McGinley Dynamic Trend System
The McGinley Dynamic, published by market technician John R. McGinley, is often described loosely as "a moving average that adjusts to volatility" without anyone showing the actual formula. This EA implements the real recursive definition: MD[i] = MD[i-1] + (Close[i] - MD[i-1]) / (N * (Close[i] / MD[i-1])^4) The ^4 term is the entire point of the indicator - it is what makes the line speed up when price is moving fast relative to its own recent position and slow down when price is chopping around it, which is genuinely different behaviour from a fixed- period EMA that responds at the same fixed rate regardless of what the market is doing. Native MQL4 has no built-in McGinley function, so it is walked by hand. Because the formula is recursive - each value depends on the previous one - the implementation recomputes the entire lookback window from scratch, oldest bar to newest, every time a new bar closes, rather than keeping one incremental running value across ticks. This avoids a subtle correctness trap: an incrementally-updated running value has nothing to fall back on if the EA is ever restarted mid-series, and would either need a saved state file or silently reseed from a wrong starting point. Recomputing the bounded window fresh each bar is more CPU work but is always correct from a clean restart with no persisted state at all. The entry rule requires two things to agree, not one: price crossing the McGinley line, AND the line's own slope already pointing the same direction as the cross. A cross into a still-flattening or opposite-sloping line is skipped - the McGinley Dynamic's own responsiveness is telling you the move has not actually accelerated into that direction yet. Notes and limitations One position at a time on the chart's own symbol; exits rely on the fixed stop/target sent with the order. The seed value (a simple average of the oldest bars in the recomputed window) is not the "true" McGinley value that a continuously-run-since-inception line would have - it is a reasonable practical seed, not a claim of matching some canonical starting point. Because the window is large (300 bars by default) relative to N=14, the seed's influence has decayed to negligible by the time the line reaches the tradable recent bars, but this is worth knowing if the raw MD values are compared against another platform's implementation with a different history length. Reseeding on every recompute means the exact MD value can differ in its tenth decimal place between a live tick and a subsequent backtest run over the same bars if the available history length differs - immaterial for the entry logic, which only reads direction and slope, but worth knowing before treating the raw MD value as a precise absolute number.
Expert advisor · MT5 · v1.0 · Free
About McGinley Dynamic Trend System
McGinley Dynamic Trend System is an expert advisor (trading robot) for MetaTrader 5 based on ATR. It can size trades from your balance and risk percent. It has 12 settings, such as Mc ginley period, Lookback bars and Atr mult sl. MQL source code included.
Files in the download: McGinleyTrendSystem.ex5, McGinleyTrendSystem.mq5, McGinleyTrendSystem.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 |
|---|---|---|
| Mc ginley period | 14 | McGinley Dynamic period N |
| Lookback bars | 300 | Bars recomputed from scratch each new bar (bounded window, oldest-first) |
| Atr mult sl | 1.5 | Stop loss distance, multiples of ATR |
| Atr mult tp | 2.5 | Take profit distance, multiples of 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 | 33301 | 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: Moving Average · Trend · Risk & Lot Size · ATR · MT5 Expert Advisor · MQL5 Source Code