NinjaTrader 8 Keltner Channel Breakout Strategy: free code and honest test
A Keltner channel breakout for NinjaTrader 8, tested on five years of MNQ data. It has the highest net profit of all 25 of our strategies, so we also tried hard to break it.
The idea
A Keltner channel draws lines a set number of ATRs above and below a moving average. A close outside the channel means price has moved unusually far in one direction, and the strategy rides that move until price returns to the average.
The exact rules
- Chart: MNQ, 5-minute bars.
- Channel = 20 EMA plus and minus 2 x ATR(14).
- Buy on a close above the upper line; sell short on a close below the lower line.
- Exit when the close crosses the 20 EMA the other way. Stop loss: 2 x ATR(14).
- Trades only from 09:35 to 15:30 Eastern; flat from 15:55. No overnight trades.
Test results (MNQ, 5 years)
Result: the highest net profit of all 25 of our strategies, and it held up when we stressed it. It made $16,477 on 2,309 trades (profit factor 1.13, average $7 a trade) with a worst drawdown of $3,905, and all 6 calendar years were positive. Longs made $7,756 and shorts $8,721, so it was not just riding a rising market. Without its five best trades it still made $8,821, and without the best ten $4,072. With double the commission and two ticks of slippage it made $11,592, and with three ticks of slippage $9,448. Caveats: it wins only 36% of its trades, one micro contract earned about $3,295 a year, and a single backtest on one instrument over one period is not proof. Results like this often fade on data a strategy has not seen. This is a good place to start your own testing, not a promise.
| With costs | Costs ignored | |
|---|---|---|
| Net profit | $16,477 | $21,260 |
| Number of trades | 2,309 | 2,303 |
| Winning trades | 36.2% | 37.1% |
| Profit factor | 1.13 | 1.17 |
| Average trade | $7 | $9 |
| Worst drawdown | -$3,905 | |
| Net without its 5 best trades | $8,821 |
Results are in US dollars for one MNQ contract. "Costs ignored" is shown only so you can see how much costs matter; it is not what you would have received.
Year by year
| Year | Net (with costs) | Trades |
|---|---|---|
| 2021 (from October) | $2,029 | 126 |
| 2022 | $4,438 | 524 |
| 2023 | $1,250 | 494 |
| 2024 | $4,484 | 509 |
| 2025 | $937 | 329 |
| 2026 (to October) | $3,339 | 327 |
Cost stress test
| Cost assumption | Net | Profit factor |
|---|---|---|
| Base costs: $0.50 per side + 1 tick slippage | $16,477 | 1.13 |
| Double commission ($1.00 per side) + 2 ticks slippage | $11,592 | 1.09 |
| $1.00 per side + 3 ticks slippage | $9,448 | 1.07 |
Real fills are often worse than a simulation, so we also ran the same trades with higher commission and more slippage. A strategy whose result disappears here is too thin to trade.
How we tested. This is our own simulation, run in Python on NinjaTrader 1-minute MNQ bars from October 2021 to October 2026 (1,466 trading days), built into 5-minute bars. Signals are read at the close of a bar and filled at the open of the next bar. Costs: $0.50 commission per side plus one tick of slippage on every market or stop fill, 1 contract, regular trading hours only, everything flat by 15:55 Eastern. Targets fill only when price trades one tick through them, and if one bar touches both the stop and the target the stop counts first. The settings are the textbook defaults, chosen before the test and never optimised. The table above is not a NinjaTrader Strategy Analyzer run, so your own backtest will differ somewhat. As a check, we ran six of these strategies (EMA Cross, Keltner, opening range breakout, Fibonacci, Renko-style and Ichimoku) in Strategy Analyzer on MNQ 03-26, 5-minute bars, 5 January to 10 March 2026, with no commission or slippage, and compared them with our simulation over the same dates: trade counts were within 5% and win rates within about 3 percentage points. That check covers those six strategies over about ten weeks, not the whole pack or the whole five years. Run your own before you trust anything.
Watch the test (4:01)
The rules, the result, and three attempts to break it, with the same numbers as this page. Captions only, no voiceover.
Simulated results, not trading results. Education only, not financial advice. Pressing play loads the video from YouTube (privacy-enhanced mode); see the privacy policy. Watch on YouTube instead.
How to use it in NinjaTrader 8
- Download the
.csfile above and save it toDocuments\NinjaTrader 8\bin\Custom\Strategies. - In NinjaTrader choose New → NinjaScript Editor, then press F5 to compile. Compiling reloads all your NinjaScript, so do it when you have no open position and nothing running live.
- To backtest, open New → Strategy Analyzer, choose VortexKeltnerBreakout, set the instrument to MNQ and a 5 Minute data series, pick a date range and run it.
- To run it on a chart, right-click the chart, choose Strategies, add VortexKeltnerBreakout, set the account and order quantity, and tick Enabled. Start on a simulated account.
- Backtest on a single contract month such as MNQ 03-26, or on a correctly merged series. In our testing a merged
MNQ ##-##series returned no trades in Strategy Analyzer, while a single contract worked. - Times in the settings use your chart's time zone. The defaults assume US Eastern time, so change them if your PC clock is in another zone.
Settings
| Channel EMA period / width | 20 / 2.0 x ATR |
|---|---|
| ATR period / stop multiple | 14 / 2.0 |
| Trade from / Last entry / Flat by | 093500 / 153000 / 155500 |
Questions
Is this strategy profitable?
See the results above, which are simulated, include costs and are shown exactly as they came out. A simulation does not predict the future, and we do not claim this strategy makes money.
Can I use it on a prop firm account?
Check your firm's rules first. Many prop firms ban automated trading, and breaking that rule can cost you your account. We do not know your firm's current rules.
Why do the results not match my NinjaTrader backtest?
Our results come from our own simulation with the fill rules stated above, not from Strategy Analyzer. Fill assumptions, data and time zones differ, so results will differ. Always run your own test.
Can I change it?
Yes. It is plain NinjaScript with the source included, so you can edit it or learn from it. Changing the settings to fit past data usually makes the past look better and the future no better, so be careful.
How much does it cost?
Nothing. It is free. If you like free tools, see the free Drawdown Panel and the Monte Carlo calculator.
← All free NinjaTrader 8 strategies · Risk & disclosures