Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-Time Frame, OnEachTick - Adding a 1-Tick Delay to Historical Backtests

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

    Multi-Time Frame, OnEachTick - Adding a 1-Tick Delay to Historical Backtests

    Hi,
    I'm using a multi-time frame script that has 10sec bars as my primary dataseries, and ticks as my secondary. I'm calculating OnEachTick. It's proving troublesome to get live results to match backtesting (I know it'll never be perfect but I know I'm quite far off currently). I don't use Bid/Ask data so I haven't developed OnMarketData for TickReplay. I 'think' I need to introduce a 1-tick delay to my backtest entries and exits, and I'm hoping to check my understanding on a few things to understand if I'm approaching the solution correctly please...

    In realtime, I always have an extra primary bar because there is always the current bar being built, and BarsInProgess 0 fires with each tick being processed (e.g. every tick received will prompt a BarsInProgress 0 OnBarUpdate, as it updates the currently being built bar). To reference the last fully built bar in reatime, I need to use Close[1], whereas in historical mode there is no bar currently being built so I need to reference Close[0]. In summary, when using OnEachTick & a secondary tick series, I need to treat realtime = Close[1] & Historical = Close[0] as equivalents? So when doing calculations and tick counting in realtime, I need to calculate on Close[1] and log my tick count series as [1], and use the equivalent [0] in historical. Is this understanding correct please?

    If I have understood this correctly, in theory I will always be one tick delayed in realtime vs historical because historical already 'knows' the bar ended when it did and doesn't need to wait an extra tick to know this, whereas realtime needs to see an extra tick before it realizes the old bar has now closed. Is this understanding correct please?

    Getting to my question. In historical, is there a way of artifically creating this one tick delay so my backtest matches how realtime would behave? I'm thinking of something along the lines of waiting until the first tick of a new 10sec bar comes through, and then calling my primary series from within my secondary series, e.g.:
    Code:
    if (historical == true)
    {
    if (BarsInProgress == 1 && ThisIsTheFirstTickSinceThePrimaryBarClosed == true)
    {
    if (Closes[0][0] > Opens[0][0])
    {
    //do something
    }
    }
    }
    
    if (historical == false)
    {
    if (BarsInProgress == 0)
    {
    if (Close[1] > Open[1]
    {
    //do something
    }
    }
    }
    Does this in theory introduce a 1 tick delay and mean the historical results should more closely mirror realtime entries/exit timings?

    Many thanks in advance

    ChainsawDR​

    #2
    Hello ChainsawDR,

    If you are using Calculate OnPriceChange or OnEachTick, this would also require TickReplay to be enabled to work historically (backtest).
    Further, implementing 1-tick intra-bar granularity for accurate order fill execution prices would be necessary.
    Below is a link to a forum post that discusses.


    Where you have mentioned:
    In realtime, I always have an extra primary bar because there is always the current bar being built, and BarsInProgess 0 fires with each tick being processed (e.g. every tick received will prompt a BarsInProgress 0 OnBarUpdate, as it updates the currently being built bar). To reference the last fully built bar in reatime, I need to use Close[1], whereas in historical mode there is no bar currently being built so I need to reference Close[0]. In summary, when using OnEachTick & a secondary tick series, I need to treat realtime = Close[1] & Historical = Close[0] as equivalents? So when doing calculations and tick counting in realtime, I need to calculate on Close[1] and log my tick count series as [1], and use the equivalent [0] in historical. Is this understanding correct please?
    This would all depend on what Calculate setting is used and if this is historical or real-time and if TickReplay is enabled.

    Below is a link to the help guide.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X