Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

trade execution live vs historical/backtest

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    trade execution live vs historical/backtest

    Hi,

    I'm having issues getting correct historical/backtest results on a strategy I've developed. When running the strategy live the trade executes as intended (a pullback strategy which executes on the first candle to make a new high which gets hihglighted in pink). But when I look at the same trade on a backtest (a couple of minutes later), that trade is not captured. The backtest only seems to capture trades for which there are continuation candles after the new high is formed ( so half or more of the trades are not reflected). I have recorded a video to show this discrepancy. You will notice that in real time the strategy execute; then a minute later i simply refresh the strategy (in the strategy menu by disabling/.enabling it back) and then you will see that the trade disappears. This happens for trades where the following candle does not continue in the same direction. This makes it really difficult to backtest this strategy as half of the trades won't fire. What can I do to make sure I see everything firing in the historical data/backtest? Happy to post the code as needed.

    Here is the link to the video:


    1st part of the vide until 1:20 is the live trading section where the trade executes, then you will see me refresh the strategy from the options menu in order to see the the same trade in historical format but you will notice that the execution disappears.
    Thank you
    Ted

    #2
    Hello snoinvest,

    Thank you for your post.

    Live orders are filled on an exchange with a trading partner on an agreed upon price based on market dynamics. Backtest / historical orders are not using these market dynamics. Instead these are filled based on logical rules from processing historical data.
    • When in historical data, only the Open, High, Low, and Close will be available and there will be no intra-bar data.
      • This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known
      • Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick' and the script will not have the intra-bar information to accurately fill an order at the exact price and time.
    Intra-bar granularity adds a second data series such as a 1 tick series using AddDataSeries() so that the strategy or indicator has the individual ticks in the historical data in between the High and Low of the primary series.

    In NinjaTrader 8, there have been two new enhancements so that programmers may not have to manually add this secondary series and code the script for high accuracy fills (Order Fill Resolution) or for intra-bar actions (TickReplay) depending on the needs of the script.

    Note: bar types that are IsRemoveLastBarSupported cannot be used with TickReplay and generally cause inaccurate results when backtesting in historical data.
    Note: High Order Fill Resolution allows for intra-bar order fills with historical processing, but is not compatible with Tick Replay.

    Please see this support article for a detailed explanation:




    If you have further questions please let us know.

    Comment


      #3
      Hi Gaby, I have backtested a strategy with the minute data over 10 years on ES. Suppose I would like to apply the Intra-bar granularity concept to allow the strategy to enter/close the position within a minute, is it only applicable for the past year as that's the longest tick data that Ninjatrader would provide? In other words, the remaining 9 years would still only enter/close the position after the bar closed? I am using Ninjatrader Continuum as my data provider. Thank you.

      Comment


        #4
        Hello morong0414,

        Note that you would need to use intrabar granularity along with Tick Replay and be using Calculate.OnPriceChange or OnEachTick in order to enter intrabar in backtest.

        Also correct, you would only be able to backtest with intrabar granularity as far as you have tick data available. You would likely get an error when the strategy starts to process bars for which you don't have any data.

        Please let us know if you have any further questions.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        58 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        133 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X