Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtesting With a Secondary Series

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

    Backtesting With a Secondary Series

    Howdy--

    I've built a swing indicator that looks for swing points, which is working fine.

    I'm now trying to back test a few ideas with this swing indicator, but I'm having some issues on getting the historical entries right.

    Here is an example of a short signal. A short swing is defined as a bar with a higher high than the bars on either side of it, and the signal bar to the left of the swing high bar must have a lower low than the swing high bar. Here's a chart.

    Click image for larger version

Name:	Backtesting With Secondary Series 1.png
Views:	1
Size:	131.3 KB
ID:	902047

    Look at the highest bar on this chart...the one that has the arrow, triangle and dot on top of it with the pink colored bar to the right of it. That's the swing high bar and the pink bar is the bar that confirmed the swing high.

    So I want to test a simple always in the market system (I'll added exits later) to get the backtesting functionality down. So on this trade, I want my short entry price to be at the level the blue line is drawn at, which is 1 tick below the low of the swing high bar. In this particular case, the swing high bar's low was 100.35, so the short entry price would be 100.34.

    As you can see, the position is filled one bar to the right of the pink signal bar at the correct price, but I want the backtest to assume that the entry is made at 100.34 within the pink bar.

    To do this, I added a secondary series within Initialize() by:

    Code:
    Add(PeriodType.Minute, 1);
    Then, within my GoShort() method, I placed a EnterShortLimit order using the secondary bars in progress of 1--plus I drew that blue line that you see.

    Code:
    #region GoShort()
    private void GoShort()
    {
            //Enter Position
    	myEntryOrder = EnterShortLimit(1, true, contracts, e, "short");
    	DrawLine("entry line" + CurrentBar, 1, e, 0, e, Color.Blue);			
    	Print("We are now done with the GoShort() Method, and we have successfully submitted a short market order.");
    }
    #endregion GoShort()
    "e" above was defined before the GoShort() method call as the entry price.

    The GoShort() method was called from within a BIP == 0 if statement within OnBarUpdate().

    I know that I will have other questions, but before I do anything else I would like to first focus on getting the strategy to execute an order within the correct signal bar. What am I doing wrong? I believe the blue line shows that I have am correctly focused on the signal bar (ie, I'm attempting to EnterShortLimit on the right bar), but the order is not getting filled until the next bar, which is not correct. In realtime, this order would have fired once the swing high was confirmed, which would have been at the point that the low of the swing high bar was taken out by the signal bar's low (ie, at the entry point), which would have triggered GoShort(), which would have fired a real time order off, which would have been filled when market conditions allowed.

    What am I missing?

    Thanks,

    Aventeren

    #2
    Hi aventeren,

    What time was the historical fill that should have happened?

    Is the time stamp before the close time of that bar?

    I understand you are adding 1 minute granularity, but the time stamp will decide what bar it is included with.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by aventeren View Post
      Howdy--

      I've built a swing indicator that looks for swing points, which is working fine.

      I'm now trying to back test a few ideas with this swing indicator, but I'm having some issues on getting the historical entries right.

      Here is an example of a short signal. A short swing is defined as a bar with a higher high than the bars on either side of it, and the signal bar to the left of the swing high bar must have a lower low than the swing high bar. Here's a chart.

      [ATTACH]30154[/ATTACH]

      Look at the highest bar on this chart...the one that has the arrow, triangle and dot on top of it with the pink colored bar to the right of it. That's the swing high bar and the pink bar is the bar that confirmed the swing high.

      So I want to test a simple always in the market system (I'll added exits later) to get the backtesting functionality down. So on this trade, I want my short entry price to be at the level the blue line is drawn at, which is 1 tick below the low of the swing high bar. In this particular case, the swing high bar's low was 100.35, so the short entry price would be 100.34.

      As you can see, the position is filled one bar to the right of the pink signal bar at the correct price, but I want the backtest to assume that the entry is made at 100.34 within the pink bar.

      To do this, I added a secondary series within Initialize() by:

      Code:
      Add(PeriodType.Minute, 1);
      Then, within my GoShort() method, I placed a EnterShortLimit order using the secondary bars in progress of 1--plus I drew that blue line that you see.

      Code:
      #region GoShort()
      private void GoShort()
      {
              //Enter Position
          myEntryOrder = EnterShortLimit(1, true, contracts, e, "short");
          DrawLine("entry line" + CurrentBar, 1, e, 0, e, Color.Blue);            
          Print("We are now done with the GoShort() Method, and we have successfully submitted a short market order.");
      }
      #endregion GoShort()
      "e" above was defined before the GoShort() method call as the entry price.

      The GoShort() method was called from within a BIP == 0 if statement within OnBarUpdate().

      I know that I will have other questions, but before I do anything else I would like to first focus on getting the strategy to execute an order within the correct signal bar. What am I doing wrong? I believe the blue line shows that I have am correctly focused on the signal bar (ie, I'm attempting to EnterShortLimit on the right bar), but the order is not getting filled until the next bar, which is not correct. In realtime, this order would have fired once the swing high was confirmed, which would have been at the point that the low of the swing high bar was taken out by the signal bar's low (ie, at the entry point), which would have triggered GoShort(), which would have fired a real time order off, which would have been filled when market conditions allowed.

      What am I missing?

      Thanks,

      Aventeren
      A 1-minute barClose/barOpen will ALWAYS coincide with barClose/barOpen in any higher minute time-based time frame. Ergo, if your trade is triggered on the close of the higher time-frame bar, then it will coincide with the open of the new bar on both time frames, and WYSIWYG.

      Comment


        #4
        Originally posted by NinjaTrader_ChelseaB View Post
        Hi aventeren,

        What time was the historical fill that should have happened?

        Is the time stamp before the close time of that bar?

        I understand you are adding 1 minute granularity, but the time stamp will decide what bar it is included with.
        The chart is a weekly CL chart.

        The swing high bar ended up being the week of 9/6/13. The signal bar that confirmed the swing high bar was the 9/13/13 weekly bar. The entry should have been made on the 9/13/13 bar, however the entry was not made until the 9/20/13 bar (ie, the bar to the right of the 9/13/13 bar).

        Here are my Output Window notes, which include the NT generated notes:

        A swing high has been confirmed at 9/13/2013 2:15:00 PM. We will now enter GoShort() and enter with a limit order with a price of 100.34
        9/13/2013 2:15:00 PM Entered internal PlaceOrder() method at 9/13/2013 2:15:00 PM: BarsInProgress=1 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=100.34 StopPrice=0 SignalName='short' FromEntrySignal=''
        We are now done with the GoShort() Method, and we have successfully submitted a short limit order at a price of 100.34
        We are now back in BIP == 0 within OnBarUpdate() after completing GoShort().
        206 104.60 100.34 -34.58 -1
        OnOrderUpdate() IOrder Info: Order='NT-00024/Sim101' Name='short' State=PendingSubmit Instrument='CL 11-14' Action=SellShort Limit price=100.34 Stop price=0 Quantity=1 Strategy='AventerenWilliams092414' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='644b5c127dd74a2b9ccda2c57aeec63b' Gtd='12/1/2099 12:00:00 AM'
        OnOrderUpdate() IOrder Info: Order='NT-00024/Sim101' Name='short' State=Accepted Instrument='CL 11-14' Action=SellShort Limit price=100.34 Stop price=0 Quantity=1 Strategy='AventerenWilliams092414' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='644b5c127dd74a2b9ccda2c57aeec63b' Gtd='12/1/2099 12:00:00 AM'
        OnOrderUpdate() IOrder Info: Order='NT-00024/Sim101' Name='short' State=Working Instrument='CL 11-14' Action=SellShort Limit price=100.34 Stop price=0 Quantity=1 Strategy='AventerenWilliams092414' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='644b5c127dd74a2b9ccda2c57aeec63b' Gtd='12/1/2099 12:00:00 AM'
        OnOrderUpdate() IOrder Info: Order='NT-00024/Sim101' Name='short' State=Filled Instrument='CL 11-14' Action=SellShort Limit price=100.34 Stop price=0 Quantity=1 Strategy='AventerenWilliams092414' Type=Limit Tif=Gtc Oco='' Filled=1 Fill price=100.34 Token='644b5c127dd74a2b9ccda2c57aeec63b' Gtd='12/1/2099 12:00:00 AM'
        So it looks like the OnBarUpdate() confirmed the swing high at the close of the 9/13/13 bar, which triggered GoShort() at the end of the 9/13/13 bar--and GoShort() placed the short limit order with a price of 100.34 at 9/13/13 2:15p.

        I then looked at the Help Guide on Multi Time Frame's How Bar Data is Referenced, and thought that maybe the fact that I had the strategy set for COBC = true was causing the code to not do what I wanted. So I changed the strategy's COBC = false...but I still get the same historical fills.

        I know this is something easy. What am I missing?

        Thanks

        Comment


          #5
          ...the problem I am trying to fix...

          Take a look at this chart:

          Click image for larger version

Name:	Backtesting with Secondary Series 2.png
Views:	1
Size:	147.3 KB
ID:	872399

          I have marked off the direction of the trades. You can see I would have entered short at the swing high, switch to long at the swing low, switched back to short on the swing high, switched long at the swing low, etc.

          But you can see in the case of the first swing high to swing low trade that we are focused on now, because price moved beyond the limit price (blue line) for the long limit entry, the long entry wasn't made, which meant that the profit from that trade wasn't shown...plus the next short was missed (I have a condition to not allow pyramiding).

          Hopefully that bit of background helps.

          Thanks,

          Aventeren

          Comment


            #6
            Originally posted by koganam View Post
            A 1-minute barClose/barOpen will ALWAYS coincide with barClose/barOpen in any higher minute time-based time frame. Ergo, if your trade is triggered on the close of the higher time-frame bar, then it will coincide with the open of the new bar on both time frames, and WYSIWYG.
            Thanks, koganam.

            When you say "then it will coincide with the open of the new bar on both time frames" are you referring to the "new" bar as to the bar that I am calling the "signal bar" that confirms the swing high (which is the bar I want my entry to be filled on) or are you calling the "new" bar the bar that follows my "signal bar"?

            Comment


              #7
              Originally posted by aventeren View Post
              Thanks, koganam.

              When you say "then it will coincide with the open of the new bar on both time frames" are you referring to the "new" bar as to the bar that I am calling the "signal bar" that confirms the swing high (which is the bar I want my entry to be filled on) or are you calling the "new" bar the bar that follows my "signal bar"?
              The new bar is the one that follows the bar on which the trade signal was triggered.

              Comment


                #8
                Originally posted by aventeren View Post
                The chart is a weekly CL chart.

                The swing high bar ended up being the week of 9/6/13. The signal bar that confirmed the swing high bar was the 9/13/13 weekly bar. The entry should have been made on the 9/13/13 bar, however the entry was not made until the 9/20/13 bar (ie, the bar to the right of the 9/13/13 bar).

                Here are my Output Window notes, which include the NT generated notes:



                So it looks like the OnBarUpdate() confirmed the swing high at the close of the 9/13/13 bar, which triggered GoShort() at the end of the 9/13/13 bar--and GoShort() placed the short limit order with a price of 100.34 at 9/13/13 2:15p.

                I then looked at the Help Guide on Multi Time Frame's How Bar Data is Referenced, and thought that maybe the fact that I had the strategy set for COBC = true was causing the code to not do what I wanted. So I changed the strategy's COBC = false...but I still get the same historical fills.

                I know this is something easy. What am I missing?

                Thanks
                In Backtest, COBC = false is meaningless, because there can be only one tick per bar anyway in that situation.

                Comment


                  #9
                  So is there any way that i can get my strategy to show an entry within the signal bar, as it would have happened real time?

                  What am I missing here?

                  Thanks--I really appreciate the help.

                  Comment


                    #10
                    Originally posted by aventeren View Post
                    So is there any way that i can get my strategy to show an entry within the signal bar, as it would have happened real time?

                    What am I missing here?

                    Thanks--I really appreciate the help.
                    Not if the trade is being triggered directly by the tick on the signal bar.

                    Comment


                      #11
                      Originally posted by koganam View Post
                      Not if the trade is being triggered directly by the tick on the signal bar.
                      Balls. So the only way to do this would be for me to have the order sitting 1 tick under the swing high bar, which would then be filled within the signal bar (which is 1 bar after the swing high bar)?

                      Man I thought there was a way to have the secondary series execute within a signal bar.

                      I feel like we've missed something here. How is anyone back testing intrabar strategies?

                      Comment


                        #12
                        Originally posted by aventeren View Post
                        Balls. So the only way to do this would be for me to have the order sitting 1 tick under the swing high bar, which would then be filled within the signal bar (which is 1 bar after the swing high bar)?

                        Man I thought there was a way to have the secondary series execute within a signal bar.

                        I feel like we've missed something here. How is anyone back testing intrabar strategies?
                        With a secondary bar series of 1-range or 1-tick.

                        Warning!: very heavy on resources.

                        Comment


                          #13
                          Originally posted by koganam View Post
                          With a secondary bar series of 1-range or 1-tick.

                          Warning!: very heavy on resources.
                          So a 1 minute bar is not indexed as a secondary series to the open and close of the primary bar? For instance, I thought that the first bar in the secondary series would have an open time equal to the open time of the primary series. If this is not the case, what is the secondary series bar anchored to?

                          And if I were to add a 1 tick secondary series, how is that series anchored to the primary series?

                          I thought that I understood this, but I may be totally wrapped around the axel now.

                          Comment


                            #14
                            Originally posted by aventeren View Post
                            So a 1 minute bar is not indexed as a secondary series to the open and close of the primary bar? For instance, I thought that the first bar in the secondary series would have an open time equal to the open time of the primary series. If this is not the case, what is the secondary series bar anchored to?
                            Yes it is. Which is exactly why you are seeing what you are seeing. The primary and secondary bars will open at the same time (after the order), because they are minute synchronized. I already stated that.

                            1-range and/or 1-tick bars are not synchronized to a minute marker, so can open intrabar; just as a 3-minute bar could conceivably open mid bar relative to a 10-minute bar, because their tick boundaries only coincide on time triggers that have both 3 and 10 as factors. A 1-minute bar open will always coincide with the open of any other minute-based bar. Remember, that is why 1 is not considered to be a prime number?
                            Last edited by koganam; 09-26-2014, 01:13 PM.

                            Comment


                              #15
                              Originally posted by koganam View Post
                              Yes it is. Which is exactly why you are seeing what you are seeing. The primary and secondary bars will open at the same time (after the order), because they are minute synchronized. I already stated that.

                              1-range and/or 1-tick bars are not synchronized to a minute marker, so can open intrabar; just as a 3-minute bar could conceivably open mid bar relative to a 10-minute bar, because their tick boundaries only coincide on time triggers that have both 3 and 10 as factors. A 1-minute bar open will always coincide with the open of any other minute-based bar. Remember, that is why 1 is not considered to be a prime number?
                              But a 1 minute bar is not time synchronized to a weekly or daily bar type?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              651 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              370 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              109 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              574 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              577 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X