Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Opening 2 contracts instead of one

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

    Opening 2 contracts instead of one

    I have a strategy that open a long position when certain conditions are met, then exit long when certain conditions are met. then open a short position when another conditions are met as well then close short positions on certain conditions. sometimes I am getting that the strategy is closing and selling position twice thus opening 2 contracts instead of one. how can I fix that in the strategy builder so that it always open one contract only? see image and code attached.
    Attached Files

    #2
    Hello babouin77,

    Thanks for your post.

    Your strategy is using the same entry and exit conditions, this means that for example, you are placing an EnterLong at the same time as ExitShort.

    An important concept to understand is that an Entry method will automatically close any position that is in the opposite direction. For example, if you are long 1 and the strategy places an EnterShort(), the short entry method will see the current 1 long and will immediately place 1 sell contract (called "Close position") to close the long position and then it will issue a 2nd sell order to leave the strategy 1 short. However, when you submit ExitLong() at the same time this method also issues a sell contract leaving you with 2 short contracts.

    As it looks like your strategy is intended to be always in, you can just remove the ExitLong(0 and ExitShort() orders.

    For reference, please review: https://ninjatrader.com/support/help...d_approach.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      but if I do that sometimes not all conditions are met to be short... sometimes it will close the long and not be in a trade because not all conditions are met to enter the short position. is there any other way to mitigate this? for example in the image attached the long position was closed but the short position was not opened because not ALL conditions are met... any help is appreciated.
      Attached Files

      Comment


        #4
        would it help if it was a condition that was not in opening a short?

        Comment


          #5
          Hello babouin77,

          Thanks for your replies.

          I was mistaken when I reviewed the strategy, your exit conditions are not exactly the same as your entry condition. So when an ExitShort or ExitLong are called this would not occur on every trade so the issue would only occur when the entry conditions are met along with the singular exit condition.

          Another approach here would be to add an entry condition that checks to see that the market position is flat, so you only enter from a flat position. This would prevent making an entry while you are in position and would prevent the unintended double order. Here is a link to the help guide that shows creating a check of the market position in the startegy builder: https://ninjatrader.com/support/help...ionComparisons
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            ok no problem. so i would add position.marketposition=marketposition.flat on entry for long and entry for short. correct?

            Comment


              #7
              Hello babouin77,

              Thanks for your reply.

              Correct, that would prevent placing an entry while there was an existing position.
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                but i noticed that it also not opening a new entry if the conditions are met... so i had a long, and it happened the conditions to close the long and open a short were met but it just closed the long but never opened the short using this method. would it be a better way to create a different condition to close the long than to open a short? because this way it is not doing the trade when it should

                Comment


                  #9
                  Hello babouin77,

                  Thanks for your post.

                  Now that you know that issuing an Exit order at the same time as an Entry order can cause a double order, you will need to figure what logic you want to ensure that that situation does not occur. Certainly checking for a flat position before entering prevents the double order error. Creating different exit conditions may help.

                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    I tried several attempts and still i could not figure it. is there a way you can help me with a logic that would prevent having to open double order. i just want to close one and open one

                    Comment


                      #11
                      Hello babouin77,

                      Thanks for your reply.

                      Are you testing your strategy on live data on a chart or playback with replay data on a chart or in the Strategy Analyzer?

                      What instrument, bar type and bar size are you using?
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        live and playback... 3 line breaks on 1 minute.

                        Comment


                          #13
                          Hello babouin77,

                          Thanks for your reply.

                          From market replay, can you identify an instrument, date, and time where the double order occurs?


                          Paul H.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by JollyWizard, 10-02-2022, 07:37 AM
                          2 responses
                          57 views
                          0 likes
                          Last Post JollyWizard  
                          Started by b16_aln, Today, 06:33 AM
                          6 responses
                          64 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by Robotman, 09-29-2022, 01:17 PM
                          16 responses
                          328 views
                          0 likes
                          Last Post zslyr
                          by zslyr
                           
                          Started by trdninstyle, Yesterday, 09:32 AM
                          23 responses
                          154 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by music_p13, Today, 08:45 AM
                          2 responses
                          29 views
                          0 likes
                          Last Post music_p13  
                          Working...
                          X