Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetAtmStrategyStopTargetOrderStatus() question

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

    GetAtmStrategyStopTargetOrderStatus() question

    If the code makes a call to:
    string[,] orders = GetAtmStrategyStopTargetOrderStatus("TARGET1", "idValue");

    And there is an error:
    ERROR: GetAtmStrategyStopTargetStatus() method error: AtmStrategyId '28ef269eebce45d78b6bbbabcf250d89' does not exist or is already in terminated state

    Is there a way to know that this strategy ID is no longer valid? Is it just that orders.Length() == 0, or is there another return status or something else I could check? In other words, could orders.Length() ever be 0 but the strategy ID is still valid?

    Thanks!
    Bryan

    #2
    I'll tell you why I'm asking too.... My code does this call to manage the ATM strategy:

    result = AtmStrategyChangeStopTarget( 0, stopprice, "Stop1", id);

    Now, in the trace file, this call shows that the order was submitted, so result = true:

    Code:
    2012-12-11 06:00:00:031 (IB) Cbi.Globals.ProcessEventArgsInThreadContext.RetryChange: Order='233255543/xxxxxxx' Name='Stop1' State=Working Instrument='NG 01-13' Action=Sell Limit price=3.449 Stop price=3.469 Quantity=1 Strategy='(null)' Type=StopLimit Tif=Day Oco='3a1f8f2f-8d1f-4b74-8532-2e2b98435dac' Filled=0 Fill price=0 Token='a079989a54fc41f7ad0920d4f017e3e8' Gtd='12/1/2099 12:00:00 AM'
    2012-12-11 06:00:00:031 (IB) Cbi.Order.Change: Order='233255543/xxxxxxx' Name='Stop1' State=Working Instrument='NG 01-13' Action=Sell Limit price=3.449 Stop price=3.469 Quantity=1 Strategy='(null)' Type=StopLimit Tif=Day Oco='3a1f8f2f-8d1f-4b74-8532-2e2b98435dac' Filled=0 Fill price=0 Token='a079989a54fc41f7ad0920d4f017e3e8' Gtd='12/1/2099 12:00:00 AM'
    2012-12-11 06:00:00:031 (IB) IB.Adapter.Change: Order='233255543/xxxxxxx' Name='Stop1' State=Working Instrument='NG 01-13' Action=Sell Limit price=3.449 Stop price=3.469 Quantity=1 Strategy='(null)' Type=StopLimit Tif=Day Oco='3a1f8f2f-8d1f-4b74-8532-2e2b98435dac' Filled=0 Fill price=0 Token='a079989a54fc41f7ad0920d4f017e3e8' Gtd='12/1/2099 12:00:00 AM'
    2012-12-11 06:00:00:032 (IB) IB.OrderRequest.Send: tmOrderId='233255543' orderId ='371' instrument='NG' expiry='201301' strikePrice=0 right='' exchange='NYMEX' action='SELL' limitPrice=3.449 auxPrice=3.469 quantity=1 type='STPLMT' tif='DAY' oca='3a1f8f2f-8d1f-4b74-8532-2e2b98435dac'
    2012-12-11 06:00:00:032 (IB) Cbi.Connection.ProcessEventArgs.OrderStatusEventArgs: Order='233255543/xxxxxxx' Name='Stop1' New state=PendingChange Instrument='NG 01-13' Action=Sell Limit price=3.449 Stop price=3.469 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''
    2012-12-11 06:00:00:032 (IB) Cbi.Order.Update1: oldid='233255543' Order='233255543/xxxxxxx' Name='Stop1' New state=PendingChange Instrument='NG 01-13' Action=Sell Limit price=3.449 Stop price=3.469 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''
    2012-12-11 06:00:00:032 (IB) Cbi.OrderStatusEventArgs.Process: Order='233255543/xxxxxxx' Name='Stop1' New state=Working Instrument='NG 01-13' Action=Sell Limit price=3.439 Stop price=3.459 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''
    But later, the broker cancelled this stop order because that market moved rapidly and the stop price became invalid before the broker processed it:

    Code:
    2012-12-11 06:00:00:580 (IB) IB.OrderRequest.Process: id='233255543' state='PendingCancel' filled=0 price=0 / Order='233255543/xxxxxxx' Name='Stop1' State=PendingChange Instrument='NG 01-13' Action=Sell Limit price=3.449 Stop price=3.469 Quantity=1 Strategy='(null)' Type=StopLimit Tif=Day Oco='3a1f8f2f-8d1f-4b74-8532-2e2b98435dac' Filled=0 Fill price=0 Token='a079989a54fc41f7ad0920d4f017e3e8' Gtd='12/1/2099 12:00:00 AM'
    2012-12-11 06:00:00:624 (IB) IB.OrderRequest.Process: id='233255543' state='Cancelled' filled=0 price=0 / Order='233255543/xxxxxxx' Name='Stop1' State=PendingChange Instrument='NG 01-13' Action=Sell Limit price=3.449 Stop price=3.469 Quantity=1 Strategy='(null)' Type=StopLimit Tif=Day Oco='3a1f8f2f-8d1f-4b74-8532-2e2b98435dac' Filled=0 Fill price=0 Token='a079989a54fc41f7ad0920d4f017e3e8' Gtd='12/1/2099 12:00:00 AM'
    2012-12-11 06:00:00:624 (IB) Cbi.Connection.ProcessEventArgs.OrderStatusEventArgs: Order='233255543/xxxxxxx' Name='Stop1' New state=Cancelled Instrument='NG 01-13' Action=Sell Limit price=3.449 Stop price=3.469 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error='Order Canceled - reason:The stop trigger price is too high relative to the current market. (202)'
    2012-12-11 06:00:00:624 (IB) Cbi.Order.Update1: oldid='233255543' Order='233255543/xxxxxxx' Name='Stop1' New state=Cancelled Instrument='NG 01-13' Action=Sell Limit price=3.449 Stop price=3.469 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error='Order Canceled - reason:The stop trigger price is too high relative to the current market. (202)'
    So how would the strategy code know that this order was actually cancelled (leaving the position with no stop!) later after getting a 'true' result? This is the reason the code kept calling GetAtmStrategyStopTargetOrderStatus().
    Last edited by cassb; 12-11-2012, 07:30 PM.

    Comment


      #3
      Hello Bryan,
      If the user or your broker cancels the order then the orders length arr will return 0.

      Unfortunately there are no other way to determine the order state.
      JoydeepNinjaTrader Customer Service

      Comment


        #4
        OK, then I have a followup... Maybe you can reproduce this scenario.

        I run Market Replay and let a strategy create a new order with a stop and target. Then I simulate the broker cancelling a stop by clicking on the red "X" on the DOM for the stop order. My strategy code does the call to GetAtmStrategyStopTargetOrderStatus("Stop1", id) on every tick, so it immediately gets an error when the stop order is gone and so the orders array length = 0. In my code, when Orders length is 0, I branch to a line that executes

        bool return=AtmStrategyClose()

        The value of 'return' = true, so I assume it found the order, but it does not close out the position with a market order or anything. The position remains open with no stop or target.

        Is there another way to close out the position besides AtmStrategyClose(), or maybe am I not using this method correctly?

        Thanks!
        Bryan

        Comment


          #5
          Hello Bryan,
          Thanks for the detailed clarification.

          I can replicate the scenario and will seek further clarification from development. Thanks for your patience.
          JoydeepNinjaTrader Customer Service

          Comment


            #6
            Hello Bryan,
            To clarify further the boolean return value does not returns whether the order was closed or not. It just indicates that the routine was called.

            We will however look into if we could enhance this in our future release.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Joydeep View Post
              Hello Bryan,
              To clarify further the boolean return value does not returns whether the order was closed or not. It just indicates that the routine was called.

              We will however look into if we could enhance this in our future release.
              Yes, I understand, thank you. I believe the help doc on that method says that the return value indicates whether the ATM ID was found or not, but does not guarantee that the order was closed. In my case, it is not closing the order, and I don't have a reason why it was not closed, or any other method I can run that would actually close that position.

              Thanks!
              Bryan

              Comment


                #8
                Hello Bryan,
                When you call the AtmStrategyClose method, NinjaTrader basically modifies the target order to close the position. When the stop order is cancelled the target also gets cancelled (OCO'ed out). Since the target order is no longer there NinjaTrader could not close the position.

                Unfortunately I am not aware of any alternative.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Joydeep View Post
                  Hello Bryan,
                  When you call the AtmStrategyClose method, NinjaTrader basically modifies the target order to close the position. When the stop order is cancelled the target also gets cancelled (OCO'ed out). Since the target order is no longer there NinjaTrader could not close the position.

                  Unfortunately I am not aware of any alternative.
                  The description of this method in the user guide says:

                  "Definition
                  Cancels any working orders and closes any open position of a strategy by first modifying any existing target orders so they are filled or submitting a market order if no target orders exist. "

                  So it will not actually send a market order then if the target no longer exists?

                  Thanks!

                  Comment


                    #10
                    Hello Bryan,
                    Once the stop has been cancelled the Atm is broken and it is no longer tied to the position. Thus the strategy will not place the market order.
                    JoydeepNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    646 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    367 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    108 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    569 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    573 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X