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.
    Eduardo R.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by dadarara, Today, 03:21 AM
    0 responses
    6 views
    0 likes
    Last Post dadarara  
    Started by rajeshks1988, 01-13-2021, 12:00 PM
    10 responses
    1,261 views
    0 likes
    Last Post konganda  
    Started by M_ichel, 04-22-2025, 02:21 PM
    7 responses
    60 views
    1 like
    Last Post brucerobinson  
    Started by michelz, 02-18-2025, 08:30 AM
    33 responses
    1,062 views
    0 likes
    Last Post MiCe1999  
    Started by volIQ, 04-23-2025, 05:43 PM
    4 responses
    38 views
    0 likes
    Last Post volIQ
    by volIQ
     
    Working...
    X