A bar that opens above the prior close but then closes under the 40 period EMA triggers a buy, as long as the 30 bar fractal dimension index is below 1.5. The mirror setup sells short. Every trade is closed exactly 4 bars later or at a 60 point stop.
Best run of 2. GBP/USD, 4 hours, spread 1.5, from run sweeps:2026-09-21-GBPUSD-4h-opt.tsv:4.
| Period | Up to 2026-09-21 |
| Instrument | GBP/USD, 4 hours |
| Spread | 1.5 points |
| Contracts | 1 |
| Starting capital | 1,000,000 |
| Costs | Spread only. Commissions and overnight financing are not included. |
| Bars | Up to 200,000 bars, fewer where the instrument has less history |
| Last tested | 2026-09-21 |
| positionSize Contracts per trade | 1 |
| emaPeriod EMA length for the signal | 40 |
| fdiPeriod Fractal dimension lookback | 30 |
| fdiThreshold Trade only when the fractal dimension is below this | 1.5 |
| maxBarsInTrade Close the trade exactly this many bars after entry | 4 |
| stopLossPoints Protective stop in points | 60 |
Every run
| Market | Timeframe | PF | Trades | Win % | Net | Max DD |
|---|---|---|---|---|---|---|
| GBP/USDBest run | 4 hours | n/a | 906 | 47.35 | 1,375 USD | -1,363 |
| DAX 40 | Daily | n/a | 358 | 31.56 | 2,147 EUR | -1,902 |
Charts
The code
// ============================================================ // Fractal Dimension EMA Reversion // ProRealAlgos Strategy Library | prorealalgos.com // Type: Mean reversion // Direction: Long & short // Timeframe tested: 4 hours // ============================================================ // --- Settings --- DEFPARAM CumulateOrders = false // --- Parameters --- positionSize = 1 // contracts per trade emaPeriod = 40 // EMA length for the signal fdiPeriod = 30 // fractal dimension lookback fdiThreshold = 1.5 // trade only when the fractal dimension is below this maxBarsInTrade = 4 // close the trade exactly this many bars after entry stopLossPoints = 60 // protective stop in points // --- Indicators --- emaValue = ExponentialAverage[emaPeriod](close) // Fractal dimension index: near 1 = trending, near 2 = choppy. // Undefined until enough history, so the filter blocks early trades. ONCE fdiValue = undefined IF BarIndex >= fdiPeriod - 1 THEN pathLength = 0 prevScaled = 0 fdiValue = 0 fdiHigh = Highest[fdiPeriod](close) fdiLow = Lowest[fdiPeriod](close) FOR i = 1 TO fdiPeriod - 1 DO IF (fdiHigh - fdiLow) > 0 THEN scaledPrice = (CustomClose[i] - fdiLow) / (fdiHigh - fdiLow) IF i > 1 THEN pathLength = pathLength + SQRT(SQUARE(scaledPrice - prevScaled) + (1 / SQUARE(fdiPeriod))) ENDIF prevScaled = scaledPrice ENDIF NEXT IF pathLength > 0 THEN fdiValue = 1 + (LOG(pathLength) + LOG(2)) / LOG(2 * fdiPeriod) ELSE fdiValue = 0 ENDIF ENDIF barsInTrade = BarIndex - TradeIndex
26 more lines: the entry and exit rules.
Setup
Questions
Yes. Entries fill at the next bar open and exits are a 4 bar time stop plus a 60 point stop, all coded.
GBP/USD 4 hours made 1,374.7 USD over 906 trades with a 47.35% win rate. DAX 40 Daily made 2,147.3 EUR over 358 trades.
The worst drawdown on GBP/USD 4 hours was 1,363.2 USD at 1 contract, close to the full profit of the test.
A 4 bar hold on 4 hour bars keeps trades to under a day of market time, which suits a short reversion idea on a currency pair.
Related
The ProRealAlgos community gets the full rules, the complete code and the automated portfolio.