Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy ExitShort(Signal Name) put me in a long

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

    Strategy ExitShort(Signal Name) put me in a long

    I have a strategy that is currently only built to go short. I used EnterShort([SignalName]) ExitShort([SignalName]). It errored today - log entry stated Cancellation rejected by the order management system - order is complete. affected order BuyToCover 1 Market.

    That's all fine, It went short it was supposed to buy to cover the short and take profit. On my end it looks like the ExitShort got fired more than once, I assume because another tick occurred before the buy order completed so the check to get out of the trade fired again. I didn't however think this would be a problem since I am using exitshort with the signal name. That wasn't the case I ended up in a long.

    I know its not on my end, there is no code to go long in the strategy at all so I am baffled if I am exiting a short and I am passing the signal name how it would end up buying a long position. Did I miss something in the documentation?
    I will look on my end to see if I can stop it from submitting multiple "ExitShort" commands. I assume it will be in the pending orders list or something but is this something I need to be aware of. If more than one exitshort is sent even with a signal will it just go long? And actually vice versa when I add longs in here will multiple exitlong's end up in a short?

    #2
    Hello TimWhitbeck,

    Thank you for your post.

    If multiple ExitShort() or ExitLong() methods are called for the same position, this will send multiple market orders to exit the position and could result in an overfill and an unwanted open position in the opposite direction. You mentioned, "I will look on my end to see if I can stop it from submitting multiple "ExitShort" commands." This can be done by using a bool variable that toggles between true/false if an exit has been submitted. For example, you could have the following:

    Code:
    if (Position.MarketPosition == MarketPosition.Long && exitSubmitted == false)
    {
    ExitLong();
    exitSubmitted = true;
    }
    
    // reset the bool once the position is flat
    if (Position.MarketPosition == MarketPosition.Flat)
    exitSubmitted = false;
    There are internal order handling rules in place to prevent unwanted positions, though these rules do not apply to market orders such as ExitLong() or EnterShort(). The rules may be found on the following page in the help guide:
    Please let us know if we may be of further assistance.

    Comment


      #3
      Can't I just check the orders collection for the submitted exit short? I should be able to pull it by the signal name right? I am still a bit confused to be honest. I am calling Exit - in this case there were no open orders. So why in the back bone if it sees there are no positions and I called exit does it not just throw an exception that an "Exit position" was called but there are no open positions? I get that with market orders timing is everything so you want to execute as quickly as possible but a quick check of positions that exist with this signal name should stop it from creating opposite entry. Anyways its a limitation I get it, I will change my code please let me know if I have to track it in my strategy with a Boolean like you said or if I am able to see it in the orders collection. Thanks Emily!

      Comment


        #4
        Hello TimWhitbeck,

        Thank you for your reply.

        You could consider a more advanced order handling approach and track order objects throughout your script. There are details related to advanced order handling here:


        With advanced order handling tactics, you could keep track of order and execution objects using the OnOrderUpdate() and OnExecutionUpdate() methods as demonstrated in the following reference sample:


        That said, if you are trading on a Rithmic or Interactive Brokers account, order and execution updates are not guaranteed to come through in a specific order. This means that you should not rely on the Order information from OnExecutionUpdate. My colleague has created some Rithmic and IB friendly examples for both the managed and unmanaged approach here:
        Hello, I see in the documentation you have fixed: 15048 Added Adapter, Rithmic Updated Rithmic API to version 11.3.0.0 Can you elaborate on that please? Will OnOrderUpdate() OnExecutionUpdate() and OnPositionUpdate() be called in the expected order?


        You asked, "So why in the back bone if it sees there are no positions and I called exit does it not just throw an exception that an "Exit position" was called but there are no open positions?"
        I suspect that what could have happened is there was an open position at the time the exit was called, so it submitted the exit order. By the time the exit was received on the broker's end, the position could have been closed which resulted in an error. That said, since the exit was a market order, which can't be canceled, the order was sent through anyway and resulted in a position being opened in the opposite direction. We could verify the order of events when this error occurred if you'd like to send us your diagnostic files. You can do this by going to the Control Center-> Help-> Email Support. Ensuring 'Log and Trace Files' is checked will include these files. This is checked by default. Please include a brief description of the error you received so we can offer an order submission analysis related to when that error occurred.

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

        Comment


          #5
          Thanks again Emily. I appreciate it. I will check out that order management. Unfortunately I am using rithmic currently because I am trading on a funded account. I am not a big fan but getting through it.

          Comment


            #6
            Hi Tim, did you ever solve this - running into the same issue. I've tried using a boolean flag as well.
            Thanks

            Comment


              #7
              Hello farawayz,

              Start by adding debugging prints and enabling TraceOrders.

              TraceOrders will allow you to see when orders are being submitted.

              Print the order.ToString() in OnOrderUpdate() to show which orders are being filled.

              Print the time and a label of the line number one line above each order method call to see which line of code is causing the behavior.

              Save the output to a text file (right-click the output window and select Save as) attach the output text file to your next post.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                farawayz - sorry I didn't see your question. Short answer is no, I tried asking the question a few ways in different forums and did not follow the logic of the answers. What I did though was start tracking if I knew I was in an order or not. My strategy runs each tick to one of the first things I did was check, if I was not supposed to be in an order and there is an order I would call the close... basically push the emergency get out of everything button and log it. I was going to collect the data of how many times this was happening but moved on to different brokers and different options. That said though I am back to Ninja because with everything I have tried I like them the best. If you have other questions or you figured it out hit me up. Thanks!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                50 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                126 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                68 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                42 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