Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Add secondary data series with Tick precision that calls OnBarUpdate() for each tick

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

    Add secondary data series with Tick precision that calls OnBarUpdate() for each tick


    I am adding a second data series with Data.BarsPerioType.Tick of the primary instrument so that I have single tick data for accuracy. Normally I develop my strategies at a higher time period for velocity of development, such as minutes or seconds, then do precise backtesting with tick data to have the most accurate results.

    Ideally I set the data series in the Strategy Analyzer to a larger timeframe such as 5 minutes so that I can easily look at the strategy analyzer chart, and then add a secondary data series in the strategy's OnStateChange configure to ticks. That way, I can run my strategy on tick-precision updates while viewing the chart with minutes.

    Unfortunately, what I am observing is that when I add 1-tick data series to the strategy analyzer is that it's not actually calling OnBarUpdate at 1-ticks. I use
    Code:
    AddDataSeries(Data.BarsPeriodType.Tick, 1);
    and I would expect OnBarUpdate to be called on the instrument for every tick on BarsInProgress == 1.

    If the strategy analyzer Data series is set to the following, I see that OnBarUpdate is called 6358910 times for BOTH BarsInProgress == 0 and BarsInProgress == 1.
    Instrument = NQ 06-23
    Type = Tick
    Value = 1

    However, if I set the strategy analyzer Data series to the following, I see that OnBarUpdate is called 3192955 times for BOTH BarsInProgress == 0 and BarsInProgress == 1.
    Instrument = NQ 06-23
    Type = Minute
    Value = 1

    The question I have is, how can I add a data series in OnStateChangeConfigure with ticks and get OnBarUpdate to run on each tick?

    Code below to reproduce.

    Code:
            protected override void OnStateChange()
            {
                ​if (State == State.Configure)
                {
                    startTime = DateTime.Now;
                    // Add tick data to BarsInProgress == 1
                    AddDataSeries(Data.BarsPeriodType.Tick, 1);
                }​
            }
    
            int[] tickAry = new int[2];
            protected override void OnBarUpdate()
            {
                tickAry[BarsInProgress]++;
             }
    ​
            void OnTermination() // i call this at the end of the strategy analyzation
            {
                for (int i = 0; i < tickAry.Length; i++)
                {
                    Print("tickAry[" + i + "] = " + tickAry[i]);
                }
            }​

    #2
    It would help to know the bar type of the base bars in your Strategy Analyzer session, whether it is OnBarClose or OnPriceChange or OnEachTick, and whether you have checked the box for tick replay.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hello euroq,

      Thanks for your post.

      To improve the accuracy of a backtest, you may use Tick Replay along with an added 1-tick series to have logic processed intra-bar and have orders filled intrabar.

      Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data, but this does not allow for intra-bar order fills. You would need to add a single-tick data series and submit orders to that single-tick data series for a strategy that uses Tick Replay.

      High Order Fill Resolution allows for intra-bar order fills with historical processing, but is not compatible with Tick Replay.

      Please reference the SampleIntrabarBacktest example and the following Help Guide links for more information.

      SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity' - https://ninjatrader.com/support/helpGuides/nt8/backtesting_ninjascript_strate.htm

      TickReplay: https://ninjatrader.com/support/help...ick_replay.htm

      Developing for Tick Replay:
      https://ninjatrader.com/support/helpGuides/nt8/developing_for__tick_replay.htm?zoom_highlightsub= developing+for+tick+replay

      Additional information may be found in this NinjaTrader Forum post:
      https://ninjatrader.com/support/forum/forum/ninjatrader-8/strategy-development/100192-comparing-real-time-historical-and-replay-performance?t=102504
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      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