Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple Exit Commands

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

    Multiple Exit Commands

    Hello,

    I have a question regarding multiple Exit commands executing at the same time. In the strategy I’m currently developing, I have an array of Exits that sometimes may overlap, causing multiple “ExitLong”, etc. commands to execute at the same time for closing a single position. The issue is that these multiple commands all send their own orders to broker, causing errors or erroneous entries in the other direction.

    I’m struggling to come up with a solution for this - how can I go about putting in a restriction that limits to one the actual Exit order sent to broker?

    #2
    Hello nickslad,

    Thanks for your post and a good question. The only solution I can suggest is to rework your code and make hard choices as to what exit will do what and make sure you have space between the exits so that you minimize the potential for overfills and rejected orders.

    We can leave this thread open for input from other community members as this is surely a topic of interest to many.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the reply.

      I've done a fair bit of searching for previous forum threads, etc. that might have dealt with the same or similar issues before but (rather unusually) haven't been able to turn up anything.

      As a backup I could potentially rework the exits as to space them out and effectively rule out such occurrences. However, either way, I think I will need to rethink this in some shape or form to make sure the unlikely doesn't eventually happen.

      I appreciate leaving this open in case anyone has any further input.

      Comment


        #4
        Are you using uniquely named Entries and the same name in the Exit?

        Comment


          #5
          Hi @sledge,

          Yes, I am using uniquely named Entries with matching names in exit. The Exits are each prompted by a specific fromEntrysignal.

          Comment


            #6
            I haven't encountered this situation in LIVE.

            I have in my code -

            if the time is between 155000 and 160000,
            if positionstatus == long,
            {
            ExitLong ( "namedEntry1" );
            ExitLong ( "namedEntry2" );
            ExitLong ( "namedEntry3" );
            }


            Only one of these entries would be open at a time.

            I should hope to hell that if namedEntry2 is the only 1 active, and that namedEntry1 is no longer LONG, that it wouldn't cause me to go short in total. That'll be really messed. Not happening in market replay.

            Would have to check to see in my case - which one is active and only ExitLong that one if this is the case.

            Comment


              #7
              Originally posted by sledge View Post
              if the time is between 155000 and 160000,
              if positionstatus == long,
              {
              ExitLong ( "namedEntry1" );
              ExitLong ( "namedEntry2" );
              ExitLong ( "namedEntry3" );
              }
              I believe I'm doing something very similar as well, as I have a backup "exit on close" condition that shuts down anything left outstanding before the close (1550), tied as well to specific named entries ("namedEntry1", etc.).

              What I will see is that I have overlapping exits that try to execute at the same time, say 3 separate ExitLong's tied to "namedEntry1". NamedExit1 is submitted to broker, followed by namedExit2, and then namedExit3. Typically, the subsequent namedExits will bounce back from the broker as something along the lines of rejected order, insufficient buying power. But if namedExit 1 fills before the subsequent exit orders get rejected, then the following orders are still outstanding and may enter in the opposite direction.

              I've piggybacked upon the constructions used in the strategy wizard for building out this strategy, but I may have to more substantially restructure the logic.

              Comment


                #8
                Originally posted by nickslad View Post
                I believe I'm doing something very similar as well, as I have a backup "exit on close" condition that shuts down anything left outstanding before the close (1550), tied as well to specific named entries ("namedEntry1", etc.).

                .
                I think I experienced something on these lines today. I hit "close" in chart trader, and thought this disabled the strategy usually... I was flat at this point.

                Well, to my surprise, The strategy was still enabled, and exitonclose fired -and closed out a non-existant position. So now I was short in the live market.

                Comment


                  #9
                  I have done the exact same thing as well. It's very disconcerting to use "close" in the chart trader and find the strategy act on a position that's no longer open. The one instance thus far in which I've used Close from chart trader I found that everything was very confused the next couple of trades, with my order status being incorrectly shown as Working on trades already filled. If I need to close a position manually I've done it lately from the broker's site.

                  ---

                  I seem to have found a solution for limiting the number of exits that execute at once. Based off of the SampleOnOrderUpdate example, I tied the Exit command to an IOrder object. The Exit can only execute if exitOrder == null. So then once the first exit is initiated, there is a value for exitOrder and no subsequent exits are initiated. Running this in Market Replay I'm only seeing a single exit go through in instances where prior versions would initiate multiple.

                  I've also piggybacked on the sample code for resetting the order object and managing it during different object statuses.

                  if (
                  exitOrder == null

                  && Position.MarketPosition == MarketPosition.Long
                  && Close[0] < Open[0]
                  etc.
                  )
                  {
                  exitOrder = ExitLong(string signalName, string fromEntrySignal)
                  }
                  As a test thus far, this appears to be doing what I wanted to accomplish. Hopefully this will be of further use to others.

                  Comment


                    #10
                    Originally posted by sledge View Post
                    I hit "close" in chart trader
                    Are you left-clicking or middle-clicking with your mouse?

                    Middle-clicking the Close button shouldn't affect your running strategy.

                    Last edited by bltdavid; 03-04-2016, 08:50 AM.

                    Comment


                      #11
                      Thanks. Nice find.

                      But I was in teamviewer. There are no instructions on how to simulate middle mouse click. Maybe I long pressed.

                      Comment


                        #12
                        Originally posted by sledge View Post
                        Thanks. Nice find.

                        But I was in teamviewer. There are no instructions on how to simulate middle mouse click. Maybe I long pressed.
                        Why would it be any different?

                        I assist trading friends using TeamViewer and never had a problem using middle-click on the mouse -- I just click/depress the wheel and that IS the click -- same as on my desktop.

                        Even rotating the wheel (to simulate scrolling) works for me through TeamViewer.

                        Practice middle-click on a chart window. (A middle-click shows bar info, and is therefore benign).

                        Comment


                          #13
                          Galaxy Note phone ... on mobile.

                          Comment


                            #14
                            Originally posted by sledge View Post
                            Galaxy Note phone ... on mobile.
                            Ah ... the missing piece is revealed ... lol

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by geddyisodin, Today, 05:20 AM
                            2 responses
                            16 views
                            0 likes
                            Last Post geddyisodin  
                            Started by hazylizard, Today, 08:38 AM
                            0 responses
                            6 views
                            0 likes
                            Last Post hazylizard  
                            Started by Max238, Today, 01:28 AM
                            5 responses
                            42 views
                            0 likes
                            Last Post Max238
                            by Max238
                             
                            Started by giulyko00, Yesterday, 12:03 PM
                            3 responses
                            12 views
                            0 likes
                            Last Post NinjaTrader_BrandonH  
                            Started by habeebft, Today, 07:27 AM
                            1 response
                            16 views
                            0 likes
                            Last Post NinjaTrader_ChristopherS  
                            Working...
                            X