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.
    BertrandNinjaTrader Customer Service

    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 zstheorist, Today, 07:52 PM
          0 responses
          7 views
          0 likes
          Last Post zstheorist  
          Started by pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          150 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Started by mattbsea, Today, 05:44 PM
          0 responses
          6 views
          0 likes
          Last Post mattbsea  
          Started by RideMe, 04-07-2024, 04:54 PM
          6 responses
          33 views
          0 likes
          Last Post RideMe
          by RideMe
           
          Started by tkaboris, Today, 05:13 PM
          0 responses
          6 views
          0 likes
          Last Post tkaboris  
          Working...
          X