Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Market Replay vs Back Test results
Collapse
X
-
Hello Malletto,
Thanks for your notes.
No, there are no means available for changing how real-time data processes as it comes from the broker/exchange. You also cannot change that real-time order fills are based on market dynamics.
You would need to use the Playback connection with Market Replay data for testing your strategies so the test results more accurately reflect real-time results.
Or, you would need to add a 1-Tick series to your script, submit orders to the added 1-tick series, and enable Tick Replay when backtesting in the Strategy Analyzer to allow your strategy to process historical data tick-by-tick as it would real-time and improve fill prices.
Please reference the SampleIntrabarBacktest example and the following Help Guide links for more information about adding intrabar granularity.
SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity' - https://ninjatrader.com/support/helpGuides/nt8/backtesting_ninjascript_strate.htm
TickReplay — https://ninjatrader.com/support/help...ick_replay.htm
Developing for Tick Replay -
https://ninjatrader.com/support/helpGuides/nt8/developing_for__tick_replay.htm?zoom_highlightsub= developing+for+tick+replay<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
-
Hello Malletto,
Thanks for your notes.
Backtests are executed on historical bars which always process with Calculate.OnBarClose. If your strategy uses OnEachTick or OnPriceChange for any logic then it won't match the backtest because that will be a difference in settings. To get similar processing you would need to run the strategy Calculate.OnBarClose in realtime and then also use prints in the strategy to verify that your logic executed identically to the backtest.
Ultimately, how your strategy executes both realtime and historically (backtest) is dependent on the logic and settings you use in the strategy.
For example, the SampleMACrossover strategy that comes default with NinjaTrader executes the same historically and realtime because it uses Calculate.OnBarClose processing and has simple conditions that don't have any realtime requirements.
You would have to go through your strategy's logic and settings to see if any of your logic relies on real-time, like using IsFirstTickOfBar for example, or using OnEachTick/OnPriceChange calculation such as for indicators used in the strategy.
If you do then real-time results will not match the backtest results and you would need to further modify your strategy logic to work OnBarClose in realtime.
That said, in general backtesting is not a reflection of what the strategy absolutely will do in real-time. It is going to provide results based on a specific set of rules and processing in a certain way which can differ from real-time.
<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
-
Hello Malletto,
Thanks for your notes.
The Strategy Analyzer uses Calculate.OnBarClose processing when backtesting a strategy.
This means that all calculations and all actions occur at the close of a bar.
This is noted on the "Discrepancies: Realtime vs Backtest" help guide page linked on post # 60.Please review that help guide page for more information on this.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
-
Hello Malletto,
Thanks for your notes.
No, I think you may be confused between how the Strategy Analyzer processes data and what bar information is available in historical data.
The Strategy Analyzer uses Calculate.OnBarClose for processing logic in a strategy when backtesting the strategy.
When in Historical Data only the OHLC information of a bar is known since that is the only information available in Historical Data.
This is noted on the "Discrepancies: Realtime vs Backtest" help guide page linked on post # 60. I suggest reading through that help guide page for details on this topic.
As previously stated: "To get similar processing you would need to run the strategy Calculate.OnBarClose in realtime and then also use prints in the strategy to verify that your logic executed identically to the backtest.
You would have to go through your strategy's logic and settings to see if any of your logic relies on real-time, like using IsFirstTickOfBar for example, or using OnEachTick/OnPriceChange calculation such as for indicators used in the strategy.
If you do then real-time results will not match the backtest results and you would need to further modify your strategy logic to work OnBarClose in realtime."
The TrendMagic indicator you are using may require Calculate.OnPriceChange or Calculate.OnEachTick processing for logic in the indicator script. Since backtests use Calculate.OnBarClose it won't match the backtest because that will be a difference in settings.
You could contact the developer of the indicator directly to confirm if the indicator requires OnPriceChange or OnEachTick for processing logic.Last edited by NinjaTrader_BrandonH; 12-04-2023, 09:03 AM.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
-
Hello Malletto,
Thanks for your notes.
Without seeing the Trend Magic script, I cannot say for certain if it uses OnPriceChange or OnEachTick processing. You would either have to view the script to see what it uses for calculations or contact the developer directly and ask them.
You could consider modifying the Trend Magic script to use Calculate.OnBarClose instead of Calculate.OnPriceChange or Calculate.OnEachTick.
Note that you should ensure that the logic in the script does not require OnPriceChange or OnEachTick processing, such as using IsFirstTickOfBar in the script which would require using OnPriceChange or OnEachTick.
Regarding the candles being different, you would need to make sure that the same exact data and data series settings are being used for both the chart window and the Strategy Analyzer backtest.
When opening a New > Chart window set to use the exact same data being tested over in the Strategy Analyzer, I see the bars match.
See this demonstratio: video.https://brandonh-ninjatrader.tinytak...Nl8yMjQ5Mzg3OALast edited by NinjaTrader_BrandonH; 12-04-2023, 09:20 AM.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
75 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
45 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
26 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
32 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
62 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment