Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Tick-level backtesting

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

    Tick-level backtesting

    I'm trying to back-test a strategy which uses signals off the 5 min chart to determine entries. However, once in a trade, I want my strategy to "monitor" the market tick by tick to determine when to exit.

    I've tried a couple different approaches to make this happen. For one, I've tried to add the 5 min data series in my strategy as such

    Add(PeriodType.Minute, 5);

    When I run my strategy on a 1 tick default data series (BarsInProgress = 0), with the 5 min bar data series added, I get the results that I expect. However, the problem with this approach is that the chart created in the backtest report is a 1-tick chart. I want to be able to view the 5 min chart in the backtest report in order to verify the accuracy of the entry mechanism.

    I've also tried to add the 1 tick data series like such:

    Add(PeriodType.Tick, 1);

    and running the strategy on a 5 min default data series. In this case, I see all kinds of weird stuff such as trades being exited before they were even entered (with like a 5 minute difference). I'm assuming additional time frames specified in a strategy need to be smaller than the default time frame specified.

    Is there a more elegant way of accomplishing what I'm going for? Can we do tick-level back testing while being able to see back-test chart reports for another time frame?

    #2
    nitro,

    In 6.5, the order in which the series are added is important. This is why you are experiencing your described behavior. I recommend you try NT7 which I believe has loosened this requirement.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I'm on NT 7.14. Still see the same behavior. I'm attaching what my back-test report looks like when I run the strategy on 5 min bars with 1-tick bars added in the strategy. As you can see, some trades stay active for 1 bars but actually have an entry time lower that's after the trade exit time
      Attached Files

      Comment


        #4
        nitro,

        I suggest you take a step back and just add Print(Time[0] + " " + BarsInProgress) into OnBarUpdate() to see the sequence of events. I am not sure where and at what time you submit for the code. As in, are you submitting to BIP1 or BIP0. In either case, please first see the sequence of events and confirm this is what you want.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks for the reply Josh but despite a lot of debugging, I haven't been able to figure a way to get this to work. I wrote the simplest of strategies (pasted below) to try to produce the correct behavior with no luck.

          Code:
                  protected override void Initialize()
                  {
                      CalculateOnBarClose = false;
                      
                      Add(PeriodType.Tick, 1);
                      Add(PeriodType.Minute, 5);
                      TraceOrders = true;
                  }
          
                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                      if(Position.MarketPosition == MarketPosition.Long)
                      {
                          if(BarsInProgress == 1)
                          {                
                              if(Close[0] >= (Position.AvgPrice + TickSize * 30))
                              {
                                  ExitLong("longEntry");
                              }
                              else if(Close[0] <= (Position.AvgPrice - TickSize * 100))
                              {
                                  ExitLong("longEntry");
                              }
                          }
                      }            
                      
                      if(Position.MarketPosition == MarketPosition.Flat)
                      {
                          if(BarsInProgress == 2)
                          {
                              if(Close[1] > Close[2])
                              {
                                  EnterLong(100, "longEntry");
                              }
                          }
                      }            
                  }
          Upon running this strategy I still see trades where exit times precede entry times.

          I would appreciate it if you'd try to run this strategy on your end to see if you are able to reproduce the correct behavior.

          Thanks

          Comment


            #6
            Nevermind, got the issue figured. Somehow I always manage to get it like 5 minutes after I post.

            I guess all I needed to do was to change the trade entry signature from

            EnterLong(100, "longEntry");

            to

            EnterLong(1, 100, "longEntry");

            so as to reference the correct BIP that should be used when the trade is taken.


            Sorry for the bother.

            Comment


              #7
              Originally posted by NinjaTrader_Josh View Post
              ... In 6.5, the order in which the series are added is important...
              Hi, Josh

              In relation to 6.5, please can you direct me to a reference that clarifies what the series order should be?

              Many thanks.

              Comment


                #8
                You can check into this one here for directions for 65 - http://www.ninjatrader-support2.com/...ead.php?t=6652
                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by adeelshahzad, Today, 03:54 AM
                5 responses
                32 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by stafe, 04-15-2024, 08:34 PM
                7 responses
                32 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by merzo, 06-25-2023, 02:19 AM
                10 responses
                823 views
                1 like
                Last Post NinjaTrader_ChristopherJ  
                Started by frankthearm, Today, 09:08 AM
                5 responses
                22 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                43 views
                0 likes
                Last Post jeronymite  
                Working...
                X