Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtesting Tick Data

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

    Backtesting Tick Data

    Hello,
    I have a strategy that is applied to a 100-tick bar chart. This strategy adds a 1 tick bar series with Add(PeriodType.Tick, 1), then prints out the close price each time OnBarUpdate() is called.

    When I run a backtest, in strategy analyzer, on this strat (just 2 days of data) I do not get the results that I expect. It seems that OnBarUpdate is not called until several ticks AFTER the first 100-tick bar (primary) has closed, even though the 1-tick series bars (secondary) have closed 99 times prior to the close of the first 100-tick bar.

    I would expect to see 99 ticks print (secondary series), then, the 100th tick is the close of the primary bar, so that should print (since the primary series has priority), then the 100th tick (secondary) should print. At this point, the primary bar close price should be the same as the 100th tick (secondary) close price.

    I have attached my code.
    I have the backtester's dataseries type set to tick and value set to 100.

    Can someone explain why this code is executing differently that I expect it to?

    TIA,
    -billy
    Attached Files

    #2
    Hi Billy, you want to run this on CalculateOnBarClose = false and then do your 100 tick bar logic inside if (FirstTickOfBar) referencing 1 bar back more to compensate for calling this on the open of the next bar. Then your 1 tick series will update intrabar of the 100 tick series.

    Comment


      #3
      Thank you for your reply, Bertrand. Unfortunately, I am still unable to get this working. I have tried setting the backtester to use both 1 and 100 as the tick value. I think I want to use 100 there, as that is to be my primary series, is that correct?

      With the backtester set to 100, I believe I should have the line:
      Add(PeriodType.Tick, 1); to set up my secondary 1-tick series. Is that correct?

      Then I should be able to:

      if((BarsInProgress == 0) && FirstTickOfBar && (CurrentBar > 0)){//primary series
      Print("Bar:" + (CurrentBar-1) + " Close:" + Close[1].ToString());
      }
      else{//secondary serirs (intrabar)
      Print("-->tickCount:" + tickCount + " CurrentBar:" + CurrentBar +
      " Close:" + Close.ToString());
      tickCount++;
      }

      ...but it doesn't work. Can anyone tell me where I'm going wrong?
      -billy

      Comment


        #4
        billyb,

        I am not sure why you are using [1] index and the offset of your CurrentBar by 1. To understand the ways the bar series are called I suggest you just do this in your OnBarUpdate() with nothing else.

        Code:
        Print("BarsInProgress: " + BarsInProgress + " " + Time[0] + " Close: " + Close[0] + " CurrentBar: " + CurrentBar);
        Do not filter it with BarsInProgress.

        Also, you have it correct. 100 tick as primary, 1 tick as secondary.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I think I have found the problem...my data does not include seconds in the time and when the primary tick series (100-tick bar) ends at the beginning of a series of ticks that all have the same time (172500 for instance) the backtester skips to the last of the "duplicate" times creating a gap in the intrabar (secondary series) output. I'm not sure how I'll skate around this problem without writing a prog to parse the data before it's imported into NT...

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          88 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          48 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          31 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          34 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          68 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X