Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy evaluating 'onBarClose' but seeking onPriceChange limit entry

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

    Strategy evaluating 'onBarClose' but seeking onPriceChange limit entry

    So if a bar condition has been met evaluating onBarClose, I am discovering that the next evaluation for entry execution HAS to be done on the next bar after... The objective is that if a price point is met anytime during the formation of that next bar, be it on the high or the low side, the goal is to fire a limit order entry in that direction for whichever condition gets met first. Therefore this is now an onPriceChange condition.

    I'm assuming this is doable, Can you guide me with a library link to see an example? Else if not please advise...

    FTR, what's going is if we have an inside bar, that bar sets off a variable bool to true which in turn now sets the stage for a limit entry. As price continues on the next bar, if whichever side high or low of that inside bar high gets breached during formation the intent is to fire a limit order x ticks further than that high or low. So an onPriceChange eval...

    Thanx

    #2
    Hello johnMoss,

    Thank you for your post.

    Based on your description, you will need to have your strategy calculate either On Price Change or On Each Tick. For any logic that you would like to have evaluated on bar close, you can put that inside of a condition that checks for if IsFirstTickOfBar is true:


    A bar close is signaled by the first tick of the next bar beginning to form, so this condition works to evaluate parts of your logic on bar close and then anything outside of that condition would still be processed when OnBarUpdate() is called on price change or on each tick. We have a reference sample that demonstrates separating logic between bar close and each tick here:


    Please let us know if we may be of further assistance.

    Comment


      #3
      Thank you Emily... I have read the documentation but not sure exactly how to implement. In the moment I simply converted strat to onPriceChange, & added this to the if conditionals:

      // Short Entry Session 1

      ((IsFirstTickOfBar == true)

      && (High[0] < High[1])
      && (Low[0] > Low[1]))


      For clarity's sake I removed other conditionals above as the primary purpose here is to evaluate for an inside bar at the close of that bar. FTR this is running on a 5 minute chart. This is apparently wrong as it is firing incorrectly..

      Comment


        #4
        Originally posted by johnMoss View Post
        Thank you Emily... I have read the documentation but not sure exactly how to implement. In the moment I simply converted strat to onPriceChange, & added this to the if conditionals:

        // Short Entry Session 1

        ((IsFirstTickOfBar == true)

        && (High[0] < High[1])
        && (Low[0] > Low[1]))


        For clarity's sake I removed other conditionals above as the primary purpose here is to evaluate for an inside bar at the close of that bar. FTR this is running on a 5 minute chart. This is apparently wrong as it is firing incorrectly..
        Please clarify further; I understand you have a bool that is toggled, and once that bool is toggled on the close of a bar, the limit order should be fired intrabar on the following bar once another condition is met, correct? This is what I'm thinking (in terms of some pseudo-code) based on my understanding
        Code:
        // this will only be evaluated on bar close
        if (IsFirstTickOfBar == true && // insert any other conditions that toggle the bool here)
        entryBool = true;
        
        // this will only be evaluated once entryBool is true and from there it will check whenever OnBarUpdate() is called, based on Calculate.OnPriceChange for example
        if (entryBool == true && // other intrabar entry conditions here)
        EnterLongLimit()
        If this is not accurate, please describe the conditions that toggle the bool and at what point after the bool is toggled you would like other conditions evaluated to submit the limit order, as well as what those conditions are.

        Please let me know if I may be of further assistance.

        Comment


          #5
          Hi Emily & Thank you again...

          Essentially you have it right.

          "I understand you have a bool that is toggled, and once that bool is toggled on the close of a bar, the limit order should be fired intrabar on the following bar once another condition is met, correct?"
          Yes...

          1. In this case we are working off of a 5 minute chart.So we are evaluating 5 minute bars for an inside bar condition, i.e. High[0] < High[1] && Low[0] > Low[1].

          2. If this occurs; then variable bool 'InsideBar' is set to true, and two variables initially defaulted to zero are now given price values as well, and they are the price based doubles of the IBHi & IBLo (the declared Inside bar high & low)

          3. Now If InsideBar = true, this sets off a watch for a break of either IBHi or IBLo & if either happens this fires a limit entry.

          So using Long specifically as example here and understanding evaluation method is onPriceChange, if we have (Close[0] >= IBHi), objective is to fire a limit order long 3 ticks above this value, so I assume this to be a stop limit order.

          Comment


            #6
            Originally posted by johnMoss View Post
            Hi Emily & Thank you again...

            Essentially you have it right.

            "I understand you have a bool that is toggled, and once that bool is toggled on the close of a bar, the limit order should be fired intrabar on the following bar once another condition is met, correct?"
            Yes...

            1. In this case we are working off of a 5 minute chart.So we are evaluating 5 minute bars for an inside bar condition, i.e. High[0] < High[1] && Low[0] > Low[1].

            2. If this occurs; then variable bool 'InsideBar' is set to true, and two variables initially defaulted to zero are now given price values as well, and they are the price based doubles of the IBHi & IBLo (the declared Inside bar high & low)

            3. Now If InsideBar = true, this sets off a watch for a break of either IBHi or IBLo & if either happens this fires a limit entry.

            So using Long specifically as example here and understanding evaluation method is onPriceChange, if we have (Close[0] >= IBHi), objective is to fire a limit order long 3 ticks above this value, so I assume this to be a stop limit order.
            Here is a more detailed snippet of what this could look like:
            Code:
            // check on each bar close if the recently closed bar's high is less than the previous bar's high and low is greater than the previous bar's low
            if (IsFirstTickOfBar && High[0] < High[1] && Low[0] > Low[1])
            {
            // if the above condition is met, toggle the bool to true and save the bar's high and low values to variables
            InsideBar = true;
            IBHi = High[0];
            IBLo = Low[0];
            }
            
            // if InsideBar has been set to true, now check, on price change, if the close price breaks IBHi or IBLo
            if (InsideBar && (Close[0] > IBHi || Close[0] < IBLo))
            // submit entry order
            Please test this out and see if it behaves in the desired way. You may also add print statements as a debugging tool to further understand your script's behavior, including when the bool value has changed and what values are being used for the Highs and Lows being checked. For more details on using prints to debug a script's behavior:


            Please feel free to reach out with any additional questions or concerns.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            53 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            130 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            70 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            44 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            49 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X