Longs trigger when the close breaks above the previous 9-bar high while the MACD histogram is rising, RSI(4) is above 63 and price holds above the 50 SMA. Shorts use a 7-bar low, a falling histogram, RSI(4) under 31 and the 500 SMA. Positions exit at the opposite channel edge with no profit target.
| positionSize Shares per trade, as published | 2 |
| longChannelPeriod Donchian length for long entries and the long stop | 9 |
| shortChannelPeriod Donchian length for short entries and the short stop | 7 |
| macdFast MACD fast length | 12 |
| macdSlow MACD slow length | 26 |
| macdSignalPeriod MACD signal length | 9 |
| rsiPeriod RSI length | 4 |
| longRsiLevel RSI must be above this to buy | 63 |
| shortRsiLevel RSI must be below this to short | 31 |
| longTrendPeriod SMA the close must be at or above to buy | 50 |
| shortTrendPeriod SMA the close must be at or below to short | 500 |
The code
// ============================================================ // Donchian MACD Breakout // ProRealAlgos Strategy Library | prorealalgos.com // Type: Breakout // Direction: Long & short // Timeframe tested: Not yet tested // ============================================================ // --- Settings --- DEFPARAM CumulateOrders = false DEFPARAM PreloadBars = 50000 // --- Parameters --- positionSize = 2 // shares per trade, as published longChannelPeriod = 9 // Donchian length for long entries and the long stop shortChannelPeriod = 7 // Donchian length for short entries and the short stop macdFast = 12 // MACD fast length macdSlow = 26 // MACD slow length macdSignalPeriod = 9 // MACD signal length rsiPeriod = 4 // RSI length longRsiLevel = 63 // RSI must be above this to buy shortRsiLevel = 31 // RSI must be below this to short longTrendPeriod = 50 // SMA the close must be at or above to buy shortTrendPeriod = 500 // SMA the close must be at or below to short // --- Indicators --- macdHistogram = MACD[macdFast, macdSlow, macdSignalPeriod](close) longChannelHigh = Highest[longChannelPeriod](high) longChannelLow = Lowest[longChannelPeriod](low) shortChannelHigh = Highest[shortChannelPeriod](high) shortChannelLow = Lowest[shortChannelPeriod](low) rsiValue = RSI[rsiPeriod](close) longTrendMA = Average[longTrendPeriod](close) shortTrendMA = Average[shortTrendPeriod](close)
20 more lines: the entry and exit rules.
Setup
Questions
The rules are written for ProOrder, but the rewritten code has not been compile-checked or backtested. Treat it as a starting point for your own testing.
None yet. It has not been backtested on this site.
The default is 2 per trade, set by the positionSize parameter. Without a backtest there is no drawdown figure, so size small until you have your own results.
The 500 SMA filter on shorts needs a lot of history, so a timeframe with long data coverage makes sense. No timeframe has been tested here yet.
Related
The ProRealAlgos community gets the full rules, the complete code and the automated portfolio.