Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    https://ninjatrader.com/support/foru...377#post773377

    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.
    https://ninjatrader.com/support/help...taIsReferenced
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by vapala, Yesterday, 06:22 AM
    4 responses
    30 views
    0 likes
    Last Post vapala
    by vapala
     
    Started by MSerag, 12-02-2022, 12:23 AM
    3 responses
    15 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Started by aligator, Yesterday, 07:13 PM
    1 response
    15 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by RideMe, Yesterday, 09:30 AM
    2 responses
    35 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Started by Mindset, 11-23-2022, 09:24 PM
    5 responses
    71 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X