Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with exit orders generating an extra one

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

    Problem with exit orders generating an extra one

    Hi team,

    I have a strategy that enter with a limit order and then exit either with another limit order or by stoploss.

    The orders are generated correctly but when the order exit with the limit order and cancels the stop order, somehow it creates an additional exit limit order that makes me enter again in the market (which i dont want)..

    I dont know what i am doing wrong here. Could someone help with this?

    I am adding a screenshot that shows the orders generated where you can see that there are 2 "ExitLimitLong". I would like to avoid the creation of the 2nd one.Click image for larger version

Name:	image.png
Views:	211
Size:	21.3 KB
ID:	1274524
    Additionally adding the piece of code where I call the exitlimit order in the "OnBarUpdate()":
    Click image for larger version

Name:	image.png
Views:	194
Size:	7.9 KB
ID:	1274525

    Thank you in advance!​

    #2
    Hello linkcou,

    From the timestamp it looks like the orders were submitted at almost the same time, are you running the script OnEachTick? If so you may need to implement a bool variable in your condition to make sure it only happens once. In the condition check if a bool is false. In the action when you submit the order set the bool to true. You could reset the variable in the entry condition so the target is ready to submit once each time the entry happens.

    JesseNinjaTrader Customer Service

    Comment


      #3
      mmm i think it makes sense, thanks! Yes, indeed i am running this OnEachTick.

      Below the piece of code with the entry condition + exit condition with the new boolean "AvoidDoubleExit". Is this what you meant?
      Click image for larger version

Name:	image.png
Views:	184
Size:	29.1 KB
ID:	1274529

      Comment


        #4
        Hello linkcou,

        Yes that looks correct, that should prevent the condition from becoming true more than once. The only other note here is that you likely want to change that order to being live until cancelled so it does not become expired similar to how your entry order is coded.


        ExitLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName, string fromEntrySignal)
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi Jesse,
          thanks for the tip. Actually I need the limit order to be updated in every bar with a new limit level.

          Do you still think it's better to add that? What is the major difference between the 2 options?

          Thanks!

          Comment


            #6
            Hello linkcou,

            If you need to update the price then adding the bool will prevent that condition from doing that. Rather than adding a bool you should likely add a condition checking for IsFirstTickOfBar so that order can be updated once per bar. That will allow the position to update once the order fills so that it will not submit a new order at the same time. You would still want to use live until cancelled in that case so the order can remain active when you are not calling it on each tick.



            JesseNinjaTrader Customer Service

            Comment


              #7
              Thanks Jesse! Quick follow-up: will that not have an impact the moment the exit limit is submitted? In most of the cases i enter and exit in the same bar so i want to prevent the exit limit to be created 1 bar after the entry order

              Below the new code. Does this work?
              Click image for larger version

Name:	image.png
Views:	190
Size:	31.1 KB
ID:	1274538

              Comment


                #8
                Hello linkcou,

                Yes that will change when it gets submitted as well if that is the only time you are submitting the order. I see that you have an entryOrder variable, if you have OnExecutionUpdate in your script that would be a good location to initially submit the order and then later from OnBarUpdate you can issue updates for each bar. I would suggest to do like the sample in the following link which submits the orders in OnExecutionUpdate based on the entry fill so its immediately protected and then updates the order later from OnBarUpdate.



                This sample does a breakeven in OnBarUpdate, you would replace that with your condition to update the order price on each first tick of bar.

                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hello Jesse, Thanks!

                  Yes, indeed i have the OnExecutionUpdate to create the stoploss order. I added the "ExitLimitL" order in the OnExecutionUpdate + update the OnBarUpdate.

                  Quick question: if i want to do the same in the short side, i should just replicate, correct?

                  See below the code updated:

                  ONEXECUTIONUPDATE:
                  Click image for larger version

Name:	image.png
Views:	195
Size:	33.3 KB
ID:	1274543
                  ONBARUPDATE:
                  Click image for larger version

Name:	image.png
Views:	186
Size:	18.7 KB
ID:	1274544

                  Comment


                    #10
                    Hi Jesse, the strategy works really well!! thanks! However, there is still something that i don't understand. See below the context:

                    I have a condition to enter in a new position only if 1 bar has passed from the last Exit limit/stop. I added the condition (see screenshot below). However, when i track this number i realized that the "ExitStopLimit" is not calculated correctly.
                    For instance, see below 2nd screenshot that shows that the last ExitStopLong happened 7 bars ago but when i print the BarsSinceExitExecution it shows 20 bars. Any idea why?

                    Click image for larger version

Name:	image.png
Views:	209
Size:	3.4 KB
ID:	1274665
                    Click image for larger version

Name:	image.png
Views:	193
Size:	201.2 KB
ID:	1274666

                    Comment


                      #11
                      Hello linkcou,

                      Yes if you want to add the short side you would need similar logic.

                      From the image I cant tell when that print is from but at the time the print was made it was 20 bars from the last exit. To find out which bar that is associated with you would need to print out the bar time along with those details.
                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        Hi Jesse,
                        Seems to be a glitch or something but now it's working well.
                        Thanks a lot for your support, it's been really helpful
                        Best,

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by gustavobp, Today, 03:15 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post gustavobp  
                        Started by gustavobp, Today, 03:00 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post gustavobp  
                        Started by nicbizz, Today, 02:14 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post nicbizz
                        by nicbizz
                         
                        Started by Ringer13, Today, 01:59 AM
                        0 responses
                        7 views
                        0 likes
                        Last Post Ringer13  
                        Started by NINZAMANA, 02-06-2025, 09:03 AM
                        2 responses
                        24 views
                        0 likes
                        Last Post Fertryd2  
                        Working...
                        X