NinjaTrader 8 Engulfing Candle Strategy: free code and honest test
An engulfing candle strategy for NinjaTrader 8, tested on five years of MNQ data. Candlestick patterns are everywhere online, so here is how one actually performed.
The idea
A bullish engulfing candle is a green candle whose body fully covers the previous red candle's body, read as buyers taking control. The strategy trades it only when it appears on the pullback side of the 20 EMA.
The exact rules
- Chart: MNQ, 5-minute bars, default CME US Index Futures ETH trading hours.
- Bullish engulfing: a green bar whose open is at or below the previous close and whose close is at or above the previous open (previous bar red). Bearish is the mirror image.
- Buy a bullish engulfing bar that closes below the 20 EMA; sell short a bearish one that closes above it. The body must be at least 0.5 x ATR(14) and the bar's range no more than 3 x ATR(14).
- Stop = the far end of the engulfing bar (at least 4 ticks). Target = 1.5 x the stop distance. Flat from 15:55.
Test results (MNQ, 5 years)
Result: it loses after costs, and even before them. It lost $6,420 over 2,464 trades (profit factor 0.93); with costs ignored it still lost $1,886. 40% of trades won, but with a 1.5-to-1 target that is not enough. Longs lost $3,385 and shorts lost $3,034. Positive calendar years: 2 of 6. A candlestick pattern that looks convincing on a chart is easy to find in hindsight; on this data it did not predict the next move.
| With costs | Costs ignored | |
|---|---|---|
| Net profit | -$6,420 | -$1,886 |
| Number of trades | 2,464 | 2,466 |
| Winning trades | 39.5% | 40.1% |
| Profit factor | 0.93 | 0.98 |
| Average trade | -$3 | -$1 |
| Worst drawdown | -$8,687 | |
| Net without its 5 best trades | -$8,510 |
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) | -$780 | 126 |
| 2022 | $22 | 552 |
| 2023 | -$138 | 571 |
| 2024 | -$6,004 | 464 |
| 2025 | $692 | 373 |
| 2026 (to October) | -$211 | 378 |
Cost stress test
| Cost assumption | Net | Profit factor |
|---|---|---|
| Base costs: $0.50 per side + 1 tick slippage | -$6,420 | 0.93 |
| Double commission ($1.00 per side) + 2 ticks slippage | -$10,625 | 0.89 |
| $1.00 per side + 3 ticks slippage | -$12,570 | 0.87 |
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.
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 VortexEngulfingCandle, 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 VortexEngulfingCandle, 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
| Pullback EMA period | 20 |
|---|---|
| Smallest body / largest range (x ATR) | 0.5 / 3.0 |
| Target (x stop distance) | 1.5 |
| 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