Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Having trouble with my entry rule

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

    Having trouble with my entry rule

    I've put together the majority of my strategy but the one part i can't seem to get right is the entry rule.

    What I've been trying to do is create a rule that enters a long position if the open of 4 candles ago is less than or equal to the close of 1 candle ago plus a gap of 2%. The way this looks is: Open[4] <= (Close[1]) * (1 + 0.02) ... and the same reverse rule for shorting -- which is coded the same, just reversed (>=) of course.

    In addition to this, it can only enter the trade if the current candle is 9:35 AM. I have the time part coded right, but the entries are just out of whack. What I am trying to accomplish with this is to go long (or short) if at 9:35 the price is 2.5% higher (or lower) than the opening price at 9:30. Pretty straight forward, I thought.

    How would I code this? Some of the entries look correct from a directional standpoint, but they aren't always following the 2% rule, and some entries are completely wrong -- going LONG when the 9:35 price is clearly lower than the 9:30 price (and vice versa for shorts).

    If anyone could help me out and show me what conditions I need to select to create the proper entry rules for long and short that'd be much appreciated.

    Thanks!

    #2
    Can you post your specific entry code if statement for 9:35?

    Are you using 1 minute bars?

    CalculateOnBarClose = true or false?

    This evening, Right now, ES is 1424.00.. so 1424 * (1.02) = 1452.48... is that what you would expect to enter long?

    4 bars ago was 1424.50 of a high.. so this is an easy entry condition to go long.

    Originally posted by cmspruill View Post
    I've put together the majority of my strategy but the one part i can't seem to get right is the entry rule.

    What I've been trying to do is create a rule that enters a long position if the open of 4 candles ago is less than or equal to the close of 1 candle ago plus a gap of 2%. The way this looks is: Open[4] <= (Close[1]) * (1 + 0.02) ... and the same reverse rule for shorting -- which is coded the same, just reversed (>=) of course.

    In addition to this, it can only enter the trade if the current candle is 9:35 AM. I have the time part coded right, but the entries are just out of whack. What I am trying to accomplish with this is to go long (or short) if at 9:35 the price is 2.5% higher (or lower) than the opening price at 9:30. Pretty straight forward, I thought.

    How would I code this? Some of the entries look correct from a directional standpoint, but they aren't always following the 2% rule, and some entries are completely wrong -- going LONG when the 9:35 price is clearly lower than the 9:30 price (and vice versa for shorts).

    If anyone could help me out and show me what conditions I need to select to create the proper entry rules for long and short that'd be much appreciated.

    Thanks!

    Comment


      #3
      Sledge,
      Thanks for the prompt reply.

      The entry code for the 9:35 time rule is: ToTime(Time[0]) == ToTime (9, 34, 0)

      That rule alone makes it so any and all trades are only executed at the open of the 9:35 candle.

      Yes, 1 minute bars, on a universe of stocks. And yes, correct, to go LONG it would be Open price * 1.02 and if at 9:35 the price is >= to that result then enter long. And the opposite for short.

      Again, this can only happen at 9:35 -- no other time during the day is the rule applicable... just at market open with that type of specific price momentum.

      Thoughts on how to program that?

      Thanks!


      Originally posted by sledge View Post
      Can you post your specific entry code if statement for 9:35?

      Are you using 1 minute bars?

      CalculateOnBarClose = true or false?

      This evening, Right now, ES is 1424.00.. so 1424 * (1.02) = 1452.48... is that what you would expect to enter long?

      4 bars ago was 1424.50 of a high.. so this is an easy entry condition to go long.

      Comment


        #4
        You should turn on the OUTPUT window, and put Print statements of your conditions to view what is going on to debug.




        Originally posted by cmspruill View Post
        Sledge,
        Thanks for the prompt reply.

        The entry code for the 9:35 time rule is: ToTime(Time[0]) == ToTime (9, 34, 0)

        That rule alone makes it so any and all trades are only executed at the open of the 9:35 candle.

        Yes, 1 minute bars, on a universe of stocks. And yes, correct, to go LONG it would be Open price * 1.02 and if at 9:35 the price is >= to that result then enter long. And the opposite for short.

        Again, this can only happen at 9:35 -- no other time during the day is the rule applicable... just at market open with that type of specific price momentum.

        Thoughts on how to program that?

        Thanks!

        Comment


          #5
          Originally posted by cmspruill View Post
          Sledge,
          Thanks for the prompt reply.

          The entry code for the 9:35 time rule is: ToTime(Time[0]) == ToTime (9, 34, 0)

          That rule alone makes it so any and all trades are only executed at the open of the 9:35 candle.

          Yes, 1 minute bars, on a universe of stocks. And yes, correct, to go LONG it would be Open price * 1.02 and if at 9:35 the price is >= to that result then enter long. And the opposite for short.

          Again, this can only happen at 9:35 -- no other time during the day is the rule applicable... just at market open with that type of specific price momentum.

          Thoughts on how to program that?

          Thanks!
          You have now disclosed the code condtitions. Could you now just post the actual code, and let us see if we can correct it, assuming that something is really wrong?

          Comment


            #6
            Originally posted by koganam View Post
            You have now disclosed the code condtitions. Could you now just post the actual code, and let us see if we can correct it, assuming that something is really wrong?
            Here is what i copied after going to "view code..."



            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
            CalculateOnBarClose = true;
            }

            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
            // Condition set 1
            if (Open[4] >= (Close[1]) * (1 + 0.02)
            && ToTime(Time[0]) == ToTime(9, 34, 0))
            {
            EnterShort(DefaultQuantity, "");
            }

            // Condition set 2
            if (Open[4] <= (Close[1]) * (1 + 0.02)
            && ToTime(Time[0]) == ToTime(9, 34, 0))
            {
            EnterLong(DefaultQuantity, "");
            }
            }


            Does this help at all?

            Comment


              #7
              Originally posted by cmspruill View Post
              Here is what i copied after going to "view code..."



              /// <summary>
              /// This method is used to configure the strategy and is called once before any strategy method is called.
              /// </summary>
              protected override void Initialize()
              {
              CalculateOnBarClose = true;
              }

              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
              // Condition set 1
              if (Open[4] >= (Close[1]) * (1 + 0.02)
              && ToTime(Time[0]) == ToTime(9, 34, 0))
              {
              EnterShort(DefaultQuantity, "");
              }

              // Condition set 2
              if (Open[4] <= (Close[1]) * (1 + 0.02)
              && ToTime(Time[0]) == ToTime(9, 34, 0))
              {
              EnterLong(DefaultQuantity, "");
              }
              }


              Does this help at all?
              You say that you are using 1 minute bars? Depending on when you want the actual evaluation to take place, then you should evaluate at 0935 hrs or 0936 hrs, not 0934 hrs. The bar that opens and is marked as 0934 hrs opens at 0933 hrs: NT timestamps bars with their end time, not start time.

              Otherwise, your code looks correct.
              Last edited by koganam; 11-02-2012, 09:49 AM.

              Comment


                #8
                Originally posted by koganam View Post
                You say that you are using 1 minute bars? Depending on when you want the actual evaluation to take place, then you should evaluate at 0935 hrs or 0936 hrs, not 0934 hrs. The bar that opens and is marked as 0934 hrs opens at 0933 hrs: NT timestamps bars with their end time, not start time.

                Otherwise, your code looks correct.
                Yes 1 minute, i did originally have 0935 as the entry time and my trades were entering 1 bar late, so i backed it up to 0934 to get it to enter on the open of 0935.

                However, you're saying this could be the source of my issue with it not reading the 2% rule correctly?

                Notice the screenshots below, in the first one you can tell the entry is obviously incorrect because the open at 9:30 is clearly above the open at bar 9:35 yet it goes LONG?? If anything it should have signaled short.. but again it still isn't 2% down so even a short signal would be wrong there.

                In the second screenshot, yes the open at 9:30 is lower than the open at 9:35 and it goes LONG, but it shouldn't have cause it wasn't a 2% increase. Notice 63.01 * 1.02 = 64.27 but it chooses to enter LONG at 63.32 at 9:35.

                This just has me so confused and i'm really wondering what is wrong with the rules for it to be doing this? Any ideas?
                Attached Files

                Comment


                  #9
                  Originally posted by cmspruill View Post

                  This just has me so confused and i'm really wondering what is wrong with the rules for it to be doing this? Any ideas?

                  Looks correct here as coded.

                  I think your logic is a little incorrect.


                  On image #1,currently condition set #2 is correctly going long.

                  "Notice the screenshots below, in the first one you can tell the entry is obviously incorrect because the open at 9:30 is clearly above the open at bar 9:35 yet it goes LONG?? If anything it should have signaled short.. but again it still isn't 2% down so even a short signal would be wrong there. "

                  based on the chart: let's say the open was 63.75.
                  and the current bar closes 63.40.

                  This is a true statement : 63.75 < (63.40*1.02) = 64.67
                  Therefore, enter long.

                  Did you mean to say : is 63.75 < (63.40*1-.02 ) = 62.13, which is FALSE. condition set #2 won't enter long.

                  Condition Set #1 would check: is 63.75 > (63.40*1.02) = 64.67.. FALSE.. no action taken.


                  For image #2

                  Same thing applies.

                  I hope this helped.

                  Comment


                    #10
                    Originally posted by sledge View Post
                    Looks correct here as coded.

                    I think your logic is a little incorrect.


                    On image #1,currently condition set #2 is correctly going long.

                    "Notice the screenshots below, in the first one you can tell the entry is obviously incorrect because the open at 9:30 is clearly above the open at bar 9:35 yet it goes LONG?? If anything it should have signaled short.. but again it still isn't 2% down so even a short signal would be wrong there. "

                    based on the chart: let's say the open was 63.75.
                    and the current bar closes 63.40.

                    This is a true statement : 63.75 < (63.40*1.02) = 64.67
                    Therefore, enter long.

                    Did you mean to say : is 63.75 < (63.40*1-.02 ) = 62.13, which is FALSE. condition set #2 won't enter long.

                    Condition Set #1 would check: is 63.75 > (63.40*1.02) = 64.67.. FALSE.. no action taken.


                    For image #2

                    Same thing applies.

                    I hope this helped.
                    Well, it is coded as described. It means that he needs to describe correctly that which he wants to code.
                    Last edited by koganam; 11-03-2012, 11:50 PM. Reason: Corrected spelling.

                    Comment

                    Latest Posts

                    Collapse

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