The first 7 bars of the session form an opening range, and a long triggers when TEMA(5) crosses above its high. Shorts need a TEMA cross below the low plus a close under yesterday's close. Stop and target both equal the range height, and open trades close at the next session's first bar.
| startingCapital Account size used for sizing | 10000 |
| riskFraction Share of capital risked per trade | 0.01 |
| sizingStopPoints Stop distance assumed when sizing, in points | 10 |
| rangeBars Bars after the session's first bar that build the opening range | 6 |
| temaPeriod TEMA length for the breakout signal | 5 |
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.
// ============================================================ // Opening Range Breakout TEMA // ProRealAlgos Strategy Library | prorealalgos.com // Type: Breakout // Direction: Long & short // Timeframe tested: Not yet tested // ============================================================ // --- Settings --- DEFPARAM CumulateOrders = false DEFPARAM PreloadBars = 1000 // --- Parameters --- startingCapital = 10000 // account size used for sizing riskFraction = 0.01 // share of capital risked per trade sizingStopPoints = 10 // stop distance assumed when sizing, in points rangeBars = 6 // bars after the session's first bar that build the opening range temaPeriod = 5 // TEMA length for the breakout signal ONCE dayBar = 0 ONCE longTrades = 0 ONCE shortTrades = 0 // --- Indicators --- // Size is fixed once on the first bar from capital, risk and the sizing stop. ONCE equity = startingCapital + StrategyProfit ONCE maxRisk = round(equity * riskFraction) ONCE positionSize = abs(round((maxRisk / sizingStopPoints) / PointValue) * PipSize) // Bar counter within the session, 0 on the first bar of a new day. IF Day <> Day[1] THEN dayBar = 0 ELSE dayBar = dayBar + 1 ENDIF temaValue = TEMA[temaPeriod](close) prevDayClose = DClose(1) // Opening range, plus a stop and target equal to its height. IF dayBar <= rangeBars THEN IF dayBar = 0 THEN rangeHigh = high rangeLow = low ENDIF IF high > rangeHigh THEN rangeHigh = high ENDIF IF low < rangeLow THEN rangeLow = low ENDIF stopDistance = rangeHigh - rangeLow targetDistance = stopDistance longTrades = 0 shortTrades = 0 ENDIF
32 more lines: the entry and exit rules.
Read this first
Questions
It is written for ProOrder, but it has not been compile-checked or backtested. Test it on demo first.
None yet. There are no results on this site.
The code sizes trades from 10000 capital, 1% risk and a 10 point sizing stop. Check what that means for the instrument you trade, as the actual stop is the range height.
The range is built from bars, so the timeframe sets its length. A faster chart gives a shorter opening window, a slower one a wider range with bigger stops.
Related
The ProRealAlgos community gets the full rules, the complete code and the automated portfolio.