Fractal Dimension Gated Trend System
An EMA crossover alone fires on plenty of moves that are really just noise walking two averages across each other - the crossover says the averages disagree, not that price is actually trending. This system adds a second, independent confirmation: the fractal dimension of the recent price path, computed with the same geometry as this catalogue's FractalAdaptiveMa indicator (John Ehlers' FRAMA) - split the lookback window into two halves plus one full-window pass, compare their price ranges, and derive a dimension between 1 (smooth, trending) and 2 (rough, effectively random). Reimplemented here as a direct per-bar snapshot rather than reused as a recursive moving average, since this system only needs the current dimension reading, not FRAMA's smoothed output line. An entry is only taken when the EMA cross agrees with the trend direction AND the measured dimension is at or below InpMaxDimension - i.e. price is behaving like a trend, not like noise that happened to cross two averages. An open position is closed early, independent of its stop or target, the moment dimension climbs back above InpExitDimension - a wider threshold than the entry gate, so ordinary noise around the entry level does not flap the position in and out on every bar. Position sizing is risk-based (InpRiskPercent of balance, sized off the symbol's own tick value and tick size), never a hardcoded contract size, which would mis-size metals, indices and JPY crosses. Exits are managed through a ticket-collect-first loop over this system's own magic number, so management never acts against a re-indexing order pool mid-loop. Notes and limitations The fractal dimension calculation needs 2 x InpFractalHalfWindow bars of clean high/low data; it will not evaluate before that much history exists. This is a whole-symbol trend filter, not a pattern detector - it says nothing about support/resistance, news events or session timing. Grid, martingale and averaging are NOT used anywhere in this system; every position is single, risk-sized and independently stopped. Only one position per magic/symbol is held at a time; a second entry signal while already in a position is ignored until the current one closes.
Expert advisor · MT4 · v1.0 · Free
About Fractal Dimension Gated Trend System
Fractal Dimension Gated Trend System is an expert advisor (trading robot) for MetaTrader 4 based on Moving Average and ATR. It can size trades from your balance and risk percent. It has 13 settings, such as Magic, Fast ema period and Slow ema period. MQL source code included.
Files in the download: FractalDimensionTrendSystem.ex4, FractalDimensionTrendSystem.mq4, FractalDimensionTrendSystem.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 |
|---|---|---|
| Magic | 20261301 | Magic number for this system's own orders |
| Fast ema period | 12 | Fast EMA period |
| Slow ema period | 34 | Slow EMA period |
| Fractal half window | 8 | Half-window for the fractal dimension calc (full window = 2x this) |
| Max dimension | 1.45 | Entries allowed only while dimension <= this (near 1 = trending) |
| Exit dimension | 1.75 | Existing position closed early if dimension climbs above this (trend lost) |
| Atr period | 14 | ATR period for stop/target distance |
| Atr stop multiple | 2.0 | Stop distance as a multiple of ATR |
| Atr target multiple | 3.0 | Take-profit distance as a multiple of ATR |
| Risk percent | 1.0 | Risk % of balance per trade |
| Max slippage points | 5 | Slippage tolerance passed to OrderSend |
| 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 4 open File → Open Data Folder, then go to MQL4 → Experts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 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: Price Action · Moving Average · Fractals · Trend · Risk & Lot Size · ATR · MT4 Expert Advisor · MQL4 Source Code