Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ensure 1 entry per limit order value via Strategy Builder

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

    Ensure 1 entry per limit order value via Strategy Builder

    Hi,
    I am working on a strategy that identifies a certain value and is supposed to enter with a short limit order at this value once. As you can see here, this first entry is what I want. I am using Stops and Targets via StrategyBuilder with methods SetStopLoss and SetProfitTarget. Whenever stop or target are already hit in the entry bar, the strategy executes the limit order again and again. Checking for market position or using a counter doesn't work as long as the exit happens in the entry bar. What can I do with this problem?
    Click image for larger version

Name:	image.png
Views:	279
Size:	51.3 KB
ID:	1340422

    #2
    Hello philmg

    Thanks for reaching out.


    An alternative to solve this issue will be to use a boolean flag to control trade entries. Only allow new positions when the flag is

    true. After entering a trade, set the flag to false, and reset it to true upon exit.


    A Bool variable can be declared in the "Input and Variables" section of the strategy builder.

    Within your Conditions and Actions, you will use the bool within the conditions to control the trade entry.


    First, you will add a new bool variable in the "Input and Variable" section of the Strategy builder.

    Within the "Conditions and Actions" section, you can create a condition that compares your bool variable to equal false. User variables > 'your bool variable', Equals, Misc > False.

    Next, in the "Actions" select Misc > Set 'your bool variable' > check the checkbox to set a value of True.



    Strategy builder

    Comment


      #3
      Thanks, but this doesn't work when the limit entry and the exit both take place in the same bar and the strategy calculates on bar close. In this case I have no chance of checking, if a trade occured for example via market position =! Flat.

      Comment


        #4
        Hello philmg​,

        Thanks for your reply.



        I created a video demonstrating how the bool variable is being used to only submit one order.

        In the video, you will find:

        -How to declare a bool variable

        -How to create a condition for this variable

        -How to change the state of the variable once an order has been submitted.

        https://drive.google.com/file/d/1xzH...usp=drive_link​​

        If you have other questions or concerns, please let us know






        Comment


          #5
          Thank you. I requested access to the file. It is not set to public access.

          Comment


            #6
            Hello philmg,

            I apologize.

            I have changed the link to public.
            You should be able to see the video.

            Feel free to reach out with any other questions.

            Comment


              #7
              Thanks, I reviewed the video. I fear there is a misunderstanding. This works great for market orders. What I was trying to implement is a limit oder on every bar until it is filled once, then the entry level becomes invalid. The problem here is, that I cant find a way to prevent another limit order be sent on the next bar, when an entry and an exit have been executed within the same bar.

              Comment


                #8
                Hello Philmg,



                Thank you for clarifying your needs.



                In this case, a different approach will be needed. You will need to use an Int variable to keep track of the trigger state of your logic and a double variable to hold the limit price for your limit order. You will use different sets to update the state of the INTVariable(TriggerState), making sure to keep your limit order alive if it doesn't get hit and ensuring that no other limit orders are submitted if your stop/profit orders are hit.



                First, you will need to declare two variables:

                -One Int variable to keep track of the trigger state of your logic. This variable is being set to 0.

                -One Double variable to hold the limit price for your limit order. This variable is being set to 0.

                Click image for larger version

Name:	2025-04-16_13-46-18.png
Views:	229
Size:	49.8 KB
ID:	1340806

                Within the Actions and conditions of your Strategy, in this example, there will be 3 different sets. On this example, I'm entering a longLimitOrder.



                Set#1

                Condition
                • Check if your position is long
                • Check if the TriggerState = 1

                Action:
                • Assign the TriggerState = 2
                Click image for larger version

Name:	2025-04-16_13-46-59.png
Views:	213
Size:	52.2 KB
ID:	1340807


                Set#2

                Condition
                • Check if the TriggerState = 0

                Action
                • Assign the desired price to your limit order variable
                Click image for larger version

Name:	2025-04-16_13-47-16.png
Views:	214
Size:	61.0 KB
ID:	1340808


                Set#3

                Condition
                • Check if market position is flat

                Action
                • Assign the TriggerState = 1
                • EnterLongLimit with the price of your limit order variable

                Click image for larger version

Name:	2025-04-16_13-48-25.png
Views:	213
Size:	56.1 KB
ID:	1340809



                This example ensures that your limit order stays alive until hit, and it will not trigger additional orders in the same bar if your StopLoss or ProfitTarget are hit.

                The key concept here is how you can use an Int and Double variable to achieve what you desire.



                Feel free to reach out with other questions.

                Comment


                  #9
                  Thank you. I fear that this still does not work. My problem is not triggering other limit orders in the same bat, but the next bar after the entry level has been executed on in the current bar with entry and exit in the same bar. When you check my chart screenshot in my first post you see that the same entry level executes again and again as long as the entry and exit are in the same bar. I can check if it has executed, if the exit is at least 1 bar later than the entry, but if both happen in the same bar I don' t know what logic can be used. I have tried to use barssinceexit and barssinceentry but it doesnt seem to work.

                  Comment


                    #10
                    Hello philmg,

                    Thanks for your reply.



                    The behavior you describe seems to be expected if there are no trigger states tracking the state of your orders. When you enter a limit order, it gets filled and stop/profit targets are set. Once the stop/profit target gets hit on the same bar, your position returns to flat, resulting in your initial order entry to become true once again.

                    That is why we use an int variable to keep track of your order's state.



                    The sample code I created demonstrates how the principle of using an int variable to achieve this.

                    In this sample code, you will see how we have 3 different sets.

                    In Set 1, the triggerState will be set to 2 when barssinceexit is greater than or equal to 0 and triggerstate is 1.

                    In Set 2, it checks if triggerstate is 0, and optionally check if the state is realtime. It will set the value for the order price variable to be submitted on the next set.

                    In Set 3,it checks if triggerState is 1, submits the limit order with the price of the price order variable.


                    If you're still unable to achieve the desired result with your script, please share with us the different sets for your conditions and actions so we can further investigate
                    Attached Files

                    Comment


                      #11
                      Thanks, will work with it in the coming week and report back here.

                      Comment


                        #12
                        I have tried to integrate what you suggested, but I am struggling to understand how this will be able to identify that the order was triggered and exited within the same bar, when the calculation only is performed on bar close. I have attached the strategy. Maybe you can help in modifying it, so that for each price the strategy only triggers once.
                        Attached Files

                        Comment


                          #13
                          Hello philmg,

                          Thanks for your reply.



                          You previously stated that you want to "prevent another limit order be sent on the next bar, when an entry and an exit have been executed within the same bar".

                          Also, "Whenever stop or target are already hit in the entry bar, the strategy executes the limit order again and again".

                          The sample I provided demonstrates, using 3 different sets, how to:
                          • keep a limit order alive until it is filled
                          • how the Trigger state is used to track when the order price is set, when the order is entered and when not to submit new orders anymore.

                          "I am struggling to understand how this will be able to identify that the order was triggered and exited within the same bar, when the calculation only is performed on bar close"

                          This script identifies when an exit order was triggered by comparing the BarsSinceExitExecution to be equal or greater than 0. This means that is this condition is true, you had an exit order on bar 0, which is the current bar. Another alternative to this condition is to compare BarsSinceExitExecution to equal BarsSinceEntryExecution. If they are equal, it means that you had an entry and exit at the same bar.

                          The key part is that once these conditions are true, the action is to set the trigger state to equal 2, therefore preventing the other sets from triggering again.

                          BarsSinceEntryExecution()

                          BarsSinceExitExecution()

                          A more advanced way to prevent a re-entry on the same price level would be to track the prices that orders have been submitted at and to never submit at that price again, you would need to unlock the script, add a List<double>, and add the price to the list each time they call the entry, and require the price to not be in the list to allow an entry.

                          Within the script you shared there's multiple issues i see.

                          The first issue that I see with your strategy is that you declared an int variable to hold the entry short price of your order. Since prices are decimal numbers, a double variable will be best suited to hold price values.

                          Also, within your script, there are issues with the sequence of your trigger state and that you never changed the trigger state to 2, where it would prevent new orders to be submitted.

                          While we cannot debug and troubleshoot the script for you, I highly recommend you start by using the sample we provided as a guide to create your own strategy.

                          Feel free to reach out with any other questions or concerns.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by NullPointStrategies, Today, 05:17 AM
                          0 responses
                          31 views
                          0 likes
                          Last Post NullPointStrategies  
                          Started by argusthome, 03-08-2026, 10:06 AM
                          0 responses
                          124 views
                          0 likes
                          Last Post argusthome  
                          Started by NabilKhattabi, 03-06-2026, 11:18 AM
                          0 responses
                          64 views
                          0 likes
                          Last Post NabilKhattabi  
                          Started by Deep42, 03-06-2026, 12:28 AM
                          0 responses
                          41 views
                          0 likes
                          Last Post Deep42
                          by Deep42
                           
                          Started by TheRealMorford, 03-05-2026, 06:15 PM
                          0 responses
                          46 views
                          0 likes
                          Last Post TheRealMorford  
                          Working...
                          X