Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Intrabar Backtest

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

    Intrabar Backtest

    I'm using SampleIntrabarBacktest.zip as an example but not getting where I need to go.

    My primary bar is 5 minute and my secondary is 1 tick.

    As a beginning, I want to enter 1 tick above the high of the previous 5 minute bar and reverse for a short when price is 1 tick below the low of the previous 5 minute bar. Please see the attachment. I had to make a couple of assumptions about what happened first on the bars but hopefully you get the idea.

    I thought the following would work but it doesn't. The entry occurs at the close of the 5 minute bar. I thought this would produce an intrabar entry of the 5 minute bar. How do I fix this so I get the intrabar entry I want?

    Code:
    if (Closes[1][0] > High[1])
        EnterLong(1,1,"Long");
    else if (Closes[1][0] < Low[1])
        EnterShort(1,1,"Short");
    Attached Files
    Last edited by Mike Winfrey; 02-19-2011, 05:19 AM.

    #2
    Mike, in which BarsInProgress context are you checking for your condition to enter?

    Comment


      #3
      I'm a bit confused by your question. Doesn't "if (Closes[1][0] > High[1]) " indicate that I'm comparing the close of the current bar on the 1 tick dataseries with the high of the last bar on the default dataseries which is 5 minute? This is where I'm a bit weak I have to admit.

      I also have the following in my OnBarUpdate


      if (BarsInProgress != 0) return;

      In fact, I attached a simple strat showing what I'm doing in the simplest form.

      At the moment it is a stop and reverse. There is no money management at all. What I am trying to do is enter a long 1 tick above the high of the previous bar and reverse to a short when price is 1 tick below the previous bar's low. I hope this makes sense. It does to me. So it should be clear to everyone reading this...yeah right! Kidding.

      Thanks, Mike
      Attached Files

      Comment


        #4
        Originally posted by Mike Winfrey View Post
        I'm a bit confused by your question. Doesn't "if (Closes[1][0] > High[1]) " indicate that I'm comparing the close of the current bar on the 1 tick dataseries with the high of the last bar on the default dataseries which is 5 minute? This is where I'm a bit weak I have to admit.

        I also have the following in my OnBarUpdate


        if (BarsInProgress != 0) return;

        In fact, I attached a simple strat showing what I'm doing in the simplest form.

        At the moment it is a stop and reverse. There is no money management at all. What I am trying to do is enter a long 1 tick above the high of the previous bar and reverse to a short when price is 1 tick below the previous bar's low. I hope this makes sense. It does to me. So it should be clear to everyone reading this...yeah right! Kidding.

        Thanks, Mike

        I learned most by using print statements to verify what is going on.

        Print ( "Close [0] =" + Close[0] + " Time[0]=" + Time[0] );
        Print ( "Closes [0][0] =" + Closes[0][0] + " Times[0][0]=" + Times[0][0] );

        add more prints for bars back, and your High[1] statement.



        Print ( " Closes[0][0] =" + Closes[0][0] + " Times[0][0]=" + Times[0][0]);
        Print ( " Closes[0][1] =" + Closes[0][1] + " Times[0][1]=" + Times[0][1]);
        Print ( " Closes[0][2] =" + Closes[0][2] + " Times[0][2]=" + Times[0][2]);
        Print ( " Closes[0][3] =" + Closes[0][3] + " Times[0][3]=" + Times[0][3]);
        Print ( " Closes[0][4] =" + Closes[0][4] + " Times[0][4]=" + Times[0][4]);

        Print ( " Closes[1][0] =" + Closes[1][0] + " Times[1][0]=" + Times[1][0]);
        Print ( " Closes[1][1] =" + Closes[1][1] + " Times[1][1]=" + Times[1][1]);
        Print ( " Closes[1][2] =" + Closes[1][2] + " Times[1][2]=" + Times[1][2]);
        Print ( " Closes[1][3] =" + Closes[1][3] + " Times[1][3]=" + Times[1][3]);
        Print ( " Closes[1][4] =" + Closes[1][4] + " Times[1][4]=" + Times[1][4]);

        Comment


          #5
          oh yeah, turn on the output window to view

          tools->output window

          Comment


            #6
            Originally posted by sledge View Post
            oh yeah, turn on the output window to view

            tools->output window

            From what I can tell:

            your tick series of 1 tick is not necessary. I think you are referring to the latest .. Isn't that the same of latest .. closes[0][0]?

            the onbarupdate fires when the 5 minute bar is finished then the check is made

            on friday es-03-11 friday 2/18...,,,

            Closes[0][0] =1339.25 Times[0][0]=2/18/2011 10:35:00 AM
            Closes[1][0] =1339.25 Times[1][0]=2/18/2011 10:34:59 AM
            High[1] = 1339.75 Low[1] = 1338.5
            Closes[0][0] =1339 Times[0][0]=2/18/2011 10:40:00 AM
            Closes[1][0] =1339 Times[1][0]=2/18/2011 10:39:59 AM
            High[1] = 1339.5 Low[1] = 1338.75
            Closes[0][0] =1340 Times[0][0]=2/18/2011 10:45:00 AM
            Closes[1][0] =1340 Times[1][0]=2/18/2011 10:44:59 AM
            High[1] = 1339.25 Low[1] = 1338.75
            EnterLong(1,1,"Long")
            Closes[0][0] =1340 Times[0][0]=2/18/2011 10:50:00 AM
            Closes[1][0] =1340 Times[1][0]=2/18/2011 10:49:59 AM
            High[1] = 1340.25 Low[1] = 1339
            Closes[0][0] =1340 Times[0][0]=2/18/2011 10:55:00 AM
            Closes[1][0] =1340 Times[1][0]=2/18/2011 10:54:59 AM
            High[1] = 1340.25 Low[1] = 1339.5
            Closes[0][0] =1338.75 Times[0][0]=2/18/2011 11:00:00 AM
            Closes[1][0] =1338.75 Times[1][0]=2/18/2011 10:59:59 AM
            High[1] = 1340.25 Low[1] = 1339.5
            EnterShort(1,1,"Short")
            Closes[0][0] =1339 Times[0][0]=2/18/2011 11:05:00 AM
            Closes[1][0] =1339 Times[1][0]=2/18/2011 11:04:57 AM
            High[1] = 1340.25 Low[1] = 1338.75
            Closes[0][0] =1340 Times[0][0]=2/18/2011 11:10:00 AM
            Closes[1][0] =1340 Times[1][0]=2/18/2011 11:09:59 AM
            High[1] = 1339.5 Low[1] = 1338.5
            EnterLong(1,1,"Long")
            Closes[0][0] =1340 Times[0][0]=2/18/2011 11:15:00 AM
            Closes[1][0] =1340 Times[1][0]=2/18/2011 11:14:59 AM
            High[1] = 1340.25 Low[1] = 1339
            Closes[0][0] =1340 Times[0][0]=2/18/2011 11:20:00 AM
            Closes[1][0] =1340 Times[1][0]=2/18/2011 11:19:59 AM
            High[1] = 1340.25 Low[1] = 1339.5







            Code:
                        if (BarsInProgress != 0)
                            return;
            
                        
                        
                        Print ( " Closes[0][0] =" + Closes[0][0] + " Times[0][0]=" + Times[0][0]);
                         Print ( " Closes[1][0] =" + Closes[1][0] + " Times[1][0]=" + Times[1][0]);
                         Print ( " High[1] = " + High[1] + "  Low[1] = " + Low[1]  );
                        
                        if (Closes[1][0] > High[1])
                            Print ( "EnterLong(1,1,\"Long\")" );
                        else if (Closes[1][0] < Low[1])
                            Print ( "EnterShort(1,1,\"Short\")");

            Comment


              #7
              Correct, if you work from BarsInProgress 0 (which is what you do if you return out of OBU if it's not from BIP 0) the conditions will trigger at the close of the 5 min bar and then submit to the tick series.

              Comment


                #8
                Thanks sledge. I use prints a lot as well. Just didn't think about using them the way you describe. thanks again

                Originally posted by sledge View Post
                I learned most by using print statements to verify what is going on.

                Print ( "Close [0] =" + Close[0] + " Time[0]=" + Time[0] );
                Print ( "Closes [0][0] =" + Closes[0][0] + " Times[0][0]=" + Times[0][0] );

                add more prints for bars back, and your High[1] statement.



                Print ( " Closes[0][0] =" + Closes[0][0] + " Times[0][0]=" + Times[0][0]);
                Print ( " Closes[0][1] =" + Closes[0][1] + " Times[0][1]=" + Times[0][1]);
                Print ( " Closes[0][2] =" + Closes[0][2] + " Times[0][2]=" + Times[0][2]);
                Print ( " Closes[0][3] =" + Closes[0][3] + " Times[0][3]=" + Times[0][3]);
                Print ( " Closes[0][4] =" + Closes[0][4] + " Times[0][4]=" + Times[0][4]);

                Print ( " Closes[1][0] =" + Closes[1][0] + " Times[1][0]=" + Times[1][0]);
                Print ( " Closes[1][1] =" + Closes[1][1] + " Times[1][1]=" + Times[1][1]);
                Print ( " Closes[1][2] =" + Closes[1][2] + " Times[1][2]=" + Times[1][2]);
                Print ( " Closes[1][3] =" + Closes[1][3] + " Times[1][3]=" + Times[1][3]);
                Print ( " Closes[1][4] =" + Closes[1][4] + " Times[1][4]=" + Times[1][4]);

                Comment


                  #9
                  Look at the picture I attached. I want the entry to be where I have the blue arrow. That is 1 tick above the previous bar high. So, how do I make the strategy produce an entry where I show the blue arrow? I attached a "MyCustomStrategy" in an earlier post that is a good point of reference.
                  Attached Files

                  Comment


                    #10
                    You will need to formulate your entry conditions with the finer tick based series, just submitting orders to it is not enough to achieve this behavior.

                    Comment


                      #11
                      Market Orders are in motion!

                      Mike,

                      My attempts at doing similar required the use of EnterLongLimit(), your 'MyCustomStrategy' is using a market order [ie 'EnterLong'] which (AFAIK) can be filled at the next price, not your specific price attempt. Your intent AIUI is to enter 1 tick above the high of the previous BA0 ...

                      iOrderL2 = EnterLongLimit(0, true, iQuantity2, (Highs[0][0]+(1*TickSize)), sENTRY2L);
                      As per the F1 help:

                      The following method variation is for experienced programmers who fully understand Advanced Order Handling concepts.

                      EnterLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName)

                      Jon
                      Last edited by Trader.Jon; 02-21-2011, 06:10 PM.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      649 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
                      576 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X