Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Coding for tick replay w/1 tick data series.

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

    Coding for tick replay w/1 tick data series.

    Hello, assuming I've written my strategy to run in realtime with onPriceChange and is coded to work with 1 minute bars. I want to modify it now to have it work in backtest with Tick Replay with a 1 tick data series added. I just want to be clear how to modify the code.

    Let's assume my strategy gets a long trigger after 3 consecutive red bars and and the trigger to enter long occurs intrabar as soon as the next bar ticks 1 tick above the previous red bar. So my code would be like this:

    Code:
    Calculate = OnPriceChange
    
    // If
    
    Close[3] < Open[3]
    && Close[2] < Open[2]
    && Close[1] < Open[1]
    && Close[0] > High[1] // Long triggered
    
    // do this
    
    EnterLong(1, "mySignal")
    So to make this work with Tick Replay. I would have to change the code. Is this correct?

    Code:
    //if
    
    Closes[0][3] < Opens[0][3]
    && Closes[0][2] < Opens[0][2]
    && Closes[0][1] < Opens[0][1]
    && Closes[1][0] > Highs[0][1] // Long triggered
    
    // do this
    EnterLong(1, 1, "mySignal")​
    Is this the correct way to do it? or should it be something like this?

    Code:
    //if
    BarsInProgress == 0
    && Close[3] < Open[3]
    && Close[2] < Open[2]
    && Close[1] < Open[1]
    
    // do this
    myInt = high[1] // set the trigger level on the primary bar series
    
    
    //if
    BarsInProgress == 1
    && Close[0] > myInt
    
    // do this
    EnterLong(1, 1, "mySignal")​
    ​​
    And a further question. If I instead coded an indicator to get the trigger to Enterlong instead of coding it within a strategy, this will run onPriceChange when running inside a backtest with TickReplay and with an aded 1 tick data series? So I could get the trigger signal intrabar? and apply to to the 1 tick data series?

    thank you.

    #2
    Hello lucyb,

    Thank you for your post.

    You would need to modify the code to add a 1 tick bar series, and then submit orders to that bar series.

    The following reference sample demonstrates how to submit your orders to a more granular secondary bar series (1 tick series) to achieve an "intrabar" fill:

    Backtesting NinjaScript Strategies with an intrabar granularity

    In this sample, the entry condition is triggered on the primary bar series if (BarsInProgress == 0), but the order is sent and filled on the secondary bar series.

    The way the bar series is determined is by the first parameter: 0 = primary bars, 1 = secondary bars, 2 = tertiary bars, etc.

    EnterLong(1, 1, "Long: 1min");

    When set to Calculate OnPriceChange, the OnBarUpdate() method is ONLY called when the price has changed intrabar OR when the bar has closed
    If the strategy is using OnPriceChange, the hosted indicator should also calculate OnPriceChange.

    "Embedded scripts, such as an indicator, within a calling parent script should not use a different Calculate property since it is already utilizing the Calculate property of the parent script (i.e. the strategy your indicator is called from)."
    Tick Replay will give a script the ability to perform intrabar actions, and 1 tick granularity will allow the strategy to fill orders intrabar.

    Please note that Tick Replay was NOT designed to provide accuracy in backtesting concerning order fills and execution and should NOT be used to expect the exact sequence of executions as running a strategy on live data. For greater order-fill resolution and accuracy in strategy backtesting, you can use the High Fill Resolution in the Strategy Analyzer. Furthermore you cannot combine both Tick Replay and High Order Fill resolution.

    I recommend reviewing the Developing for Tick Replay page of the Help Guide:
    Developing for Tick Replay

    Please let me know if you have any further questions.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    111 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    60 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    38 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    43 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    79 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X