A fractal high starts a falling trend line, and a two-step break of that line arms a buy stop 0.3 ATR(7) above the recent high. Exits use an exponential band and RSI(2), closing longs once RSI is at 85 or higher and price is back below the upper band. Shorts mirror the logic.
Best run of 8. USD/JPY, 4 hours, spread 1, from run sweeps:2026-09-17-USDJPY-4h-opt.tsv:2.
| Period | Up to 2026-09-17 |
| Instrument | USD/JPY, 4 hours |
| Spread | 1 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-17 |
| positionSize Contracts per trade | 1 |
| fractalBars Bars the centre of the 5-bar fractal must beat (structural, keep at 4) | 4 |
| breakoutBars Bars used for the breakout high or low | 2 |
| atrPeriod ATR length for the entry buffer | 7 |
| atrMultiplier Entry buffer beyond the breakout level, in ATRs | 0.3 |
| bandPeriod Length of the exponential log-price bands | 34 |
| seedPeriod SMA length used to seed the bands on early bars | 3 |
| bandWidth Band width in standard deviations | 1.618 |
| rsiPeriod RSI length for the exit | 2 |
| overboughtLevel RSI level a long exit needs | 85 |
| oversoldLevel RSI level a short exit needs | 15 |
| lookbackPeriod Window for the prior swing high and low | 100 |
Every run
| Market | Timeframe | PF | Trades | Win % | Net | Max DD |
|---|---|---|---|---|---|---|
| USD/JPYBest run | 4 hours | n/a | 819 | 53.36 | 161,440 JPY | -93,910 |
| USD/JPY | Daily | n/a | 300 | 59.00 | 754,540 JPY | -174,840 |
| Nikkei 225 | Daily | n/a | 262 | 61.07 | 20,201 USD | -12,694 |
| Silver | Daily | n/a | 255 | 50.59 | 8,055 USD | -2,895 |
| Brent Crude | Daily | n/a | 119 | 60.50 | 4,755 EUR | -4,645 |
| GBP/USD | Daily | n/a | 334 | 59.88 | 3,432 USD | -2,003 |
| FTSE 100 | Daily | n/a | 297 | 54.55 | 2,325 EUR | -948 |
| Gold | Daily | n/a | 287 | 55.05 | 624 EUR | -317 |
Charts
The code
Every file in the library uses the same header, the same section order and the same variable names. The numbers above were produced by the original version before the rewrite, and the rewrite has not yet been compiled in ProRealTime.
// ============================================================ // Trend Breakout // ProRealAlgos Strategy Library | prorealalgos.com // Type: Breakout // Direction: Long & short // Timeframe tested: 4 hours // ============================================================ // --- Settings --- DEFPARAM CumulateOrders = false // --- Parameters --- positionSize = 1 // contracts per trade fractalBars = 4 // bars the centre of the 5-bar fractal must beat, keep at 4 breakoutBars = 2 // bars for the breakout high / low atrPeriod = 7 // ATR length for the entry buffer atrMultiplier = 0.3 // entry buffer beyond the breakout level, in ATRs bandPeriod = 34 // length of the log-price exponential bands seedPeriod = 3 // SMA used to seed the bands on early bars bandWidth = 1.618 // band width in standard deviations rsiPeriod = 2 // RSI length for the exit overboughtLevel = 85 // long exit needs RSI at or above this oversoldLevel = 15 // short exit needs RSI at or below this lookbackPeriod = 100 // window for the prior swing high / low // State, seeded so every value is defined on the first bar. ONCE fractalHighCount = 0 ONCE fractalLowCount = 0 ONCE trendBreak = 0 ONCE bearSetup = 0 ONCE bullSetup = 0 ONCE fractalHigh = 0 ONCE fractalLow = 0 ONCE fractalBar = 0 ONCE trendHeight = 0 ONCE closeHeight = 0 ONCE maxAngle = 0 ONCE logEma = 0 ONCE logVariance = 0 ONCE longExitArmed = 0 ONCE shortExitArmed = 0 // --- Indicators --- // Count how many of the last five bars the bar two back beats. FOR i = 0 TO fractalBars DO IF high[2] > high[i] THEN fractalHighCount = fractalHighCount + 1 ENDIF IF low[2] < low[i] THEN fractalLowCount = fractalLowCount + 1 ENDIF NEXT // A fractal high starts a bearish trend line, a fractal low a bullish one. IF fractalHighCount = fractalBars THEN IF bearSetup = 0 AND bullSetup = 0 THEN bearSetup = 1 ENDIF fractalHigh = high[2] fractalBar = BarIndex - 2 ENDIF IF fractalLowCount = fractalBars THEN IF bearSetup = 0 AND bullSetup = 0 THEN bullSetup = 1 ENDIF fractalLow = low[2] fractalBar = BarIndex - 2 ENDIF fractalHighCount = 0 fractalLowCount = 0 IF bearSetup = 1 THEN trendHeight = fractalHigh - high closeHeight = fractalHigh - close ELSIF bullSetup = 1 THEN trendHeight = low - fractalLow closeHeight = close - fractalLow ENDIF // Track the steepest angle of the trend line from the fractal, then detect // a two-step break of that line (trendBreak 1, then 2). IF BarIndex - 2 = fractalBar THEN maxAngle = Tan(2 / trendHeight) ENDIF IF BarIndex - 2 > fractalBar THEN IF bearSetup = 1 THEN IF Tan((BarIndex - fractalBar) / trendHeight) > maxAngle AND (close < open OR close < close[1]) THEN maxAngle = Tan((BarIndex - fractalBar) / trendHeight) trendBreak = 0 ENDIF IF trendBreak = 0 AND Tan((BarIndex - fractalBar) / closeHeight) > maxAngle AND close > open THEN trendBreak = 1 ELSIF trendBreak = 1 AND Tan(((BarIndex - 1) - fractalBar) / closeHeight) > maxAngle AND close > close[1] THEN trendBreak = 2 ENDIF ELSIF bullSetup = 1 THEN IF Tan((BarIndex - fractalBar) / trendHeight) > maxAngle AND (close > open OR close > close[1]) THEN maxAngle = Tan((BarIndex - fractalBar) / trendHeight) trendBreak = 0 ENDIF IF trendBreak = 0 AND Tan((BarIndex - fractalBar) / closeHeight) > maxAngle AND close < open THEN trendBreak = 1 ELSIF trendBreak = 1 AND Tan(((BarIndex - 1) - fractalBar) / closeHeight) > maxAngle AND close < close[1] THEN trendBreak = 2 ENDIF ENDIF ENDIF atrValue = AverageTrueRange[atrPeriod](close)
67 more lines: the entry and exit rules.
Read this first
Questions
Yes, entries are pending stop orders valid for one bar. The code has been rewritten but not compile-checked, and the stats are from the earlier version.
All seven rows were profitable. USD/JPY Daily made JPY 754,540 over 300 trades, and Nikkei 225 Daily made USD 20,201.20.
At 1 contract the best run had a max drawdown of JPY 93,910. Gold Daily was much smaller at EUR 317.10.
Trend lines drawn from fractals need enough bars between swing points. Every tested row used 4 hour or Daily bars.
Related
The ProRealAlgos community gets the full rules, the complete code and the automated portfolio.