Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

ChangeOrder not working as expected

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

    ChangeOrder not working as expected

    Hi,
    The ChangeOrder method doesn't seem to be working as expected in my strategy. I'm following managed orders approach. Here is the flow of calls to order methods in my strategy:

    1. In OnBarUpdate():
    Code:
    SetStopLoss(signalNameLong, CalculationMode.Price, stopLoss, false);
    2.
    Code:
    EnterLong(defaultQuantity, signalNameLong);
    3. In OnOrderUpdate():
    Code:
    buyStopLossOrder.IsLiveUntilCancelled = true;
    4.
    Code:
    ChangeOrder(buyStopLossOrder, buyStopLossOrder.Quantity, 0, stopLoss);
    I did make sure that the ChangeOrder method is getting triggered. However, the stop doesn't move. Here are the log and trace statements from an example. In this example, the original stop loss was set at 9522.25. The ChangeOrder() tried to move it to 9534.

    Code:
    2020-05-25 21:47:00:473|1|32|Order='e3b25d5cb10b4f4784810b5e650d59d2/Sim101' Name='Stop loss' New state='Change submitted' Instrument='NQ 06-20' Action='Sell' Limit price=0 Stop price=[B]9534 [/B]Quantity=1 Type='Stop Market' Time in force=GTC Oco='40b5aff15a62416abb8818d70414d851' Filled=0 Fill price=0 Error='No error' Native error=''
    2020-05-25 21:47:00:582|1|32|Order='e3b25d5cb10b4f4784810b5e650d59d2/Sim101' Name='Stop loss' New state='Accepted' Instrument='NQ 06-20' Action='Sell' Limit price=0 Stop price=[B]9522.25[/B] Quantity=1 Type='Stop Market' Time in force=GTC Oco='40b5aff15a62416abb8818d70414d851' Filled=0 Fill price=0 Error='No error' Native error=''
    Code:
    2020-05-25 21:47:00:472 (My NinjaTrader Continuum) Cbi.Account.Change0: realOrderState=Accepted orderId='e3b25d5cb10b4f4784810b5e650d59d2' account='Sim101' name='Stop loss' orderState=ChangePending instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=[B]9522.25[/B] quantity=1 tif=Gtc oco='40b5aff15a62416abb8818d70414d851' filled=0 averageFillPrice=0 onBehalfOf='' id=12677 time='2020-05-25 21:47:00' gtd='2099-12-01' statementDate='2020-05-25' limitPriceChanged=0 stopPriceChanged=9534 quantityChanged=1
    2020-05-25 21:47:00:472 (My NinjaTrader Continuum) Cbi.Account.OrderUpdateCallback: realOrderState=ChangePending orderId='e3b25d5cb10b4f4784810b5e650d59d2' account='Sim101' name='Stop loss' orderState=ChangePending instrument='NQ 06-20' orderAction=Sell limitPrice=0 stopPrice=9522.25 quantity=1 orderType='Stop Market' filled=0 averageFillPrice=0 time='2020-05-25 21:47:00' statementDate='2020-05-25' error=NoError comment='' nr=-1
    2020-05-25 21:47:00:473 (My NinjaTrader Continuum) Cbi.Account.Change1: realOrderState=ChangePending orderId='e3b25d5cb10b4f4784810b5e650d59d2' account='Sim101' name='Stop loss' orderState=ChangeSubmitted instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=9534 quantity=1 tif=Gtc oco='40b5aff15a62416abb8818d70414d851' filled=0 averageFillPrice=0 onBehalfOf='' id=12677 time='2020-05-25 21:47:00' gtd='2099-12-01' statementDate='2020-05-25' limitPriceChanged=0 quantityChanged=1 stopPriceChanged=9534
    2020-05-25 21:47:00:473 (My NinjaTrader Continuum) Cbi.Simulator.Change: realOrderState=ChangePending orderId='e3b25d5cb10b4f4784810b5e650d59d2' account='Sim101' name='Stop loss' orderState=ChangeSubmitted instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=9534 quantity=1 tif=Gtc oco='40b5aff15a62416abb8818d70414d851' filled=0 averageFillPrice=0 onBehalfOf='' id=12677 time='2020-05-25 21:47:00' gtd='2099-12-01' statementDate='2020-05-25' limitPriceChanged='0' quantityChanged='1' stopPriceChanged='9534' delay=100
    2020-05-25 21:47:00:473 (My NinjaTrader Continuum) Cbi.Account.OrderUpdateCallback: realOrderState=ChangeSubmitted orderId='e3b25d5cb10b4f4784810b5e650d59d2' account='Sim101' name='Stop loss' orderState=ChangeSubmitted instrument='NQ 06-20' orderAction=Sell limitPrice=0 stopPrice=9534 quantity=1 orderType='Stop Market' filled=0 averageFillPrice=0 time='2020-05-25 21:47:00' statementDate='2020-05-25' error=NoError comment='' nr=-1
    2020-05-25 21:47:00:473 (My NinjaTrader Continuum) Cbi.Account.Change0: realOrderState=ChangeSubmitted orderId='e3b25d5cb10b4f4784810b5e650d59d2' account='Sim101' name='Stop loss' orderState=ChangePending instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=9534 quantity=1 tif=Gtc oco='40b5aff15a62416abb8818d70414d851' filled=0 averageFillPrice=0 onBehalfOf='' id=12677 time='2020-05-25 21:47:00' gtd='2099-12-01' statementDate='2020-05-25' limitPriceChanged=0 stopPriceChanged=9522.25 quantityChanged=1
    2020-05-25 21:47:00:473 (My NinjaTrader Continuum) Cbi.Account.OrderUpdateCallback: realOrderState=ChangePending orderId='e3b25d5cb10b4f4784810b5e650d59d2' account='Sim101' name='Stop loss' orderState=ChangePending instrument='NQ 06-20' orderAction=Sell limitPrice=0 stopPrice=9534 quantity=1 orderType='Stop Market' filled=0 averageFillPrice=0 time='2020-05-25 21:47:00' statementDate='2020-05-25' error=NoError comment='' nr=163
    2020-05-25 21:47:00:473 (My NinjaTrader Continuum) Cbi.Account.QueueChange: realOrderState=ChangeSubmitted orderId='e3b25d5cb10b4f4784810b5e650d59d2' account='Sim101' name='Stop loss' orderState=ChangePending instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=9534 quantity=1 tif=Gtc oco='40b5aff15a62416abb8818d70414d851' filled=0 averageFillPrice=0 onBehalfOf='' id=12677 time='2020-05-25 21:47:00' gtd='2099-12-01' statementDate='2020-05-25'
    2020-05-25 21:47:00:582 (My NinjaTrader Continuum) Cbi.Account.OrderUpdateCallback: realOrderState=Accepted orderId='e3b25d5cb10b4f4784810b5e650d59d2' account='Sim101' name='Stop loss' orderState=Accepted instrument='NQ 06-20' orderAction=Sell limitPrice=0 stopPrice=9522.25 quantity=1 orderType='Stop Market' filled=0 averageFillPrice=0 time='2020-05-25 21:47:00' statementDate='2020-05-25' error=NoError comment='' nr=-1
    2020-05-25 21:47:00:582 (My NinjaTrader Continuum) Cbi.Account.OrderUpdateCallback.DiscardRetryChange: orderId='e3b25d5cb10b4f4784810b5e650d59d2' account='Sim101' name='Stop loss' orderState=Accepted instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=9522.25 quantity=1 tif=Gtc oco='40b5aff15a62416abb8818d70414d851' filled=0 averageFillPrice=0 onBehalfOf='' id=12677 time='2020-05-25 21:47:00' gtd='2099-12-01' statementDate='2020-05-25' limitPriceChanged=0 stopPriceChanged=9522.25 quantityChanged=1
    This is in Sim account. Could you advise what I'm doing wrong?

    Thanks,
    CV
    Last edited by chaitunt; 05-26-2020, 08:05 AM.

    #2
    Hi CV. thanks for your question.

    It's possible that the price of 9522.25 was above the asking price at the time. Try turning on TraceOrders in State.SetDefault then observe the output window when you run the strategy. Are there any orders being ignored when the order change happens?

    I look forward to hearing from you.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris:
      Thanks for the response. I have captured the details requested and here they are. In this example, the original stop loss was 9450.75, which was then moved up to 9459.75. I do see the new stop loss reflected in stopPriceChanged (highlighted in green below) but by the time the order state has changed to Accepted the stop price is reset to the original stop loss at 9450.75.

      Code:
      5/26/2020 12:33:00 PM Strategy 'MyATTSStrategy123/180191970': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='123 Long: Sim101: NQ 06-20' Mode=Price Value=9450.73 IsSimulatedStop=False IsMarketIfTouched=False
      5/26/2020 12:33:00 PM Strategy 'MyATTSStrategy123/180191970': Entered internal SubmitOrderManaged() method at 5/26/2020 12:33:00 PM: BarsInProgress=2 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='123 Long: Sim101: NQ 06-20' FromEntrySignal=''
      Sim101             >>5/26/2020 12:33:00 PM NQ 06-20>>Entered [B]Long [/B]at [B]9459 [/B]with Stop Loss at: [B]9450.73[/B]
      +++++ Stop loss Order Details: orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' orderState=Submitted instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=9450.75 quantity=1 tif=Gtc oco='5becdc7743304666abc6012e9dbe6c1d' filled=0 averageFillPrice=0 onBehalfOf='' id=12778 time='2020-05-26 12:33:00' gtd='2099-12-01' statementDate='2020-05-26'
      +++++ Stop loss Order Details: orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' orderState=[B]Accepted [/B]instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 [B]stopPrice=9450.75[/B] quantity=1 tif=Gtc oco='5becdc7743304666abc6012e9dbe6c1d' filled=0 averageFillPrice=0 onBehalfOf='' id=12778 time='2020-05-26 12:33:00' gtd='2099-12-01' statementDate='2020-05-26'
      5/26/2020 12:37:00 PM Strategy 'MyATTSStrategy123/180191970': [B]Changed custom managed orde[/B]r: orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' [B]orderState=Accepted[/B] instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 [B]stopPrice=9450.75[/B] quantity=1 tif=Gtc oco='5becdc7743304666abc6012e9dbe6c1d' filled=0 averageFillPrice=0 onBehalfOf='' id=12778 time='2020-05-26 12:33:00' gtd='2099-12-01' statementDate='2020-05-26' limitPriceChanged=0 quantityChanged=1[B] [COLOR=#008000]stopPriceChanged=9459.25[/COLOR][/B]
      +++++ Stop loss Order Details: orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' [B]orderState=ChangePending[/B] instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 [B]stopPrice=9450.75[/B] quantity=1 tif=Gtc oco='5becdc7743304666abc6012e9dbe6c1d' filled=0 averageFillPrice=0 onBehalfOf='' id=12778 time='2020-05-26 12:37:00' gtd='2099-12-01' statementDate='2020-05-26'
      +++++ Stop loss Order Details: orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' [B]orderState=ChangeSubmitted[/B] instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=9459.25 quantity=1 tif=Gtc oco='5becdc7743304666abc6012e9dbe6c1d' filled=0 averageFillPrice=0 onBehalfOf='' id=12778 time='2020-05-26 12:37:00' gtd='2099-12-01' statementDate='2020-05-26'
      Sim101 5/26/2020 12:37:00 PM=====Min profit for break even has been reached.. moving stop loss to break even at 9459.25
      5/26/2020 12:37:00 PM Strategy 'MyATTSStrategy123/180191970': Amended stop order orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' orderState=ChangeSubmitted instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=9459.25 quantity=1 tif=Gtc oco='5becdc7743304666abc6012e9dbe6c1d' filled=0 averageFillPrice=0 onBehalfOf='' id=12778 time='2020-05-26 12:37:00' gtd='2099-12-01' statementDate='2020-05-26'
      +++++ Stop loss Order Details: orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' [B]orderState=ChangePending[/B] instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 [COLOR=#008000][B]stopPrice=9459.25[/B][/COLOR] quantity=1 tif=Gtc oco='5becdc7743304666abc6012e9dbe6c1d' filled=0 averageFillPrice=0 onBehalfOf='' id=12778 time='2020-05-26 12:37:00' gtd='2099-12-01' statementDate='2020-05-26'
      +++++ Stop loss Order Details: orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' [B]orderState=Accepted[/B] instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 [COLOR=#FF0000][B]stopPrice=9450.75[/B][/COLOR] quantity=1 tif=Gtc oco='5becdc7743304666abc6012e9dbe6c1d' filled=0 averageFillPrice=0 onBehalfOf='' id=12778 time='2020-05-26 12:37:00' gtd='2099-12-01' statementDate='2020-05-26'
      Here is the log information from the above period:
      Code:
       2020-05-26 12:37:00:772|1|32|Order='29422f77d32649bba1aedbfc6d5b19c3/Sim101' Name='Stop loss' New state='Change submitted' Instrument='NQ 06-20' Action='Sell' Limit price=0 Stop price=9459.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='5becdc7743304666abc6012e9dbe6c1d' Filled=0 Fill price=0 Error='No error' Native error=''
      2020-05-26 12:37:00:878|1|32|Order='29422f77d32649bba1aedbfc6d5b19c3/Sim101' Name='Stop loss' New state='Accepted' Instrument='NQ 06-20' Action='Sell' Limit price=0 Stop price=9450.75 Quantity=1 Type='Stop Market' Time in force=GTC Oco='5becdc7743304666abc6012e9dbe6c1d' Filled=0 Fill price=0 Error='No error' Native error=''

      Comment


        #4

        And trace. The last 2 statements seem to be interesting.
        Code:
         
        2020-05-26 12:37:00:771 (My NinjaTrader Continuum) Cbi.Account.Change0: realOrderState=Accepted orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' orderState=ChangePending instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=9450.75 quantity=1 tif=Gtc oco='5becdc7743304666abc6012e9dbe6c1d' filled=0 averageFillPrice=0 onBehalfOf='' id=12778 time='2020-05-26 12:37:00' gtd='2099-12-01' statementDate='2020-05-26' limitPriceChanged=0 stopPriceChanged=9459.25 quantityChanged=1
        2020-05-26 12:37:00:771 (My NinjaTrader Continuum) Cbi.Account.OrderUpdateCallback: realOrderState=ChangePending orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' orderState=ChangePending instrument='NQ 06-20' orderAction=Sell limitPrice=0 stopPrice=9450.75 quantity=1 orderType='Stop Market' filled=0 averageFillPrice=0 time='2020-05-26 12:37:00' statementDate='2020-05-26' error=NoError comment='' nr=-1
        2020-05-26 12:37:00:772 (My NinjaTrader Continuum) Cbi.Account.Change1: realOrderState=ChangePending orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' orderState=ChangeSubmitted instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=9459.25 quantity=1 tif=Gtc oco='5becdc7743304666abc6012e9dbe6c1d' filled=0 averageFillPrice=0 onBehalfOf='' id=12778 time='2020-05-26 12:37:00' gtd='2099-12-01' statementDate='2020-05-26' limitPriceChanged=0 quantityChanged=1 stopPriceChanged=9459.25
        2020-05-26 12:37:00:772 (My NinjaTrader Continuum) Cbi.Simulator.Change: realOrderState=ChangePending orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' orderState=ChangeSubmitted instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=9459.25 quantity=1 tif=Gtc oco='5becdc7743304666abc6012e9dbe6c1d' filled=0 averageFillPrice=0 onBehalfOf='' id=12778 time='2020-05-26 12:37:00' gtd='2099-12-01' statementDate='2020-05-26' limitPriceChanged='0' quantityChanged='1' stopPriceChanged='9459.25' delay=100
        2020-05-26 12:37:00:772 (My NinjaTrader Continuum) Cbi.Account.OrderUpdateCallback: realOrderState=ChangeSubmitted orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' orderState=ChangeSubmitted instrument='NQ 06-20' orderAction=Sell limitPrice=0 stopPrice=9459.25 quantity=1 orderType='Stop Market' filled=0 averageFillPrice=0 time='2020-05-26 12:37:00' statementDate='2020-05-26' error=NoError comment='' nr=-1
        2020-05-26 12:37:00:772 (My NinjaTrader Continuum) Cbi.Account.Change0: realOrderState=ChangeSubmitted orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' orderState=ChangePending instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=9459.25 quantity=1 tif=Gtc oco='5becdc7743304666abc6012e9dbe6c1d' filled=0 averageFillPrice=0 onBehalfOf='' id=12778 time='2020-05-26 12:37:00' gtd='2099-12-01' statementDate='2020-05-26' limitPriceChanged=0 stopPriceChanged=9450.75 quantityChanged=1
        2020-05-26 12:37:00:772 (My NinjaTrader Continuum) Cbi.Account.OrderUpdateCallback: realOrderState=ChangePending orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' orderState=ChangePending instrument='NQ 06-20' orderAction=Sell limitPrice=0 stopPrice=9459.25 quantity=1 orderType='Stop Market' filled=0 averageFillPrice=0 time='2020-05-26 12:37:00' statementDate='2020-05-26' error=NoError comment='' nr=-1
        2020-05-26 12:37:00:772 (My NinjaTrader Continuum) Cbi.Account.QueueChange: realOrderState=ChangeSubmitted orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' orderState=ChangePending instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=9459.25 quantity=1 tif=Gtc oco='5becdc7743304666abc6012e9dbe6c1d' filled=0 averageFillPrice=0 onBehalfOf='' id=12778 time='2020-05-26 12:37:00' gtd='2099-12-01' statementDate='2020-05-26'
        [B]2020-05-26 12:37:00:878 (My NinjaTrader Continuum) Cbi.Account.OrderUpdateCallback: realOrderState=Accepted orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' orderState=Accepted instrument='NQ 06-20' orderAction=Sell limitPrice=0 [COLOR=#FF0000]stopPrice=9450.75[/COLOR] quantity=1 orderType='Stop Market' filled=0 averageFillPrice=0 time='2020-05-26 12:37:00' statementDate='2020-05-26' error=NoError comment='' nr=-1[/B]
        [B]2020-05-26 12:37:00:878 (My NinjaTrader Continuum) Cbi.Account.OrderUpdateCallback.[COLOR=#FF0000]DiscardRetryChange[/COLOR]: orderId='29422f77d32649bba1aedbfc6d5b19c3' account='Sim101' name='Stop loss' orderState=Accepted instrument='NQ 06-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=9450.75 quantity=1 tif=Gtc oco='5becdc7743304666abc6012e9dbe6c1d' filled=0 averageFillPrice=0 onBehalfOf='' id=12778 time='2020-05-26 12:37:00' gtd='2099-12-01' statementDate='2020-05-26' limitPriceChanged=0 [COLOR=#FF0000]stopPriceChanged=9450.75[/COLOR] quantityChanged=1[/B]
        The stop loss seems to be getting reset to the original. I'm not sure by what. Please let me know your thoughts.
        Thanks,
        CV

        Comment


          #5
          Hi chaitunt, thanks for your reply.

          I'm not completely sure about the issue without some code examples. We have an existing example here that shows how to change the price of a stop loss or profit target order here:



          Please let me know if you have any questions about this material.

          Chris L.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by swestendorf, Today, 11:14 AM
          2 responses
          5 views
          0 likes
          Last Post NinjaTrader_Kimberly  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          4 responses
          12 views
          0 likes
          Last Post xiinteractive  
          Started by Mupulen, Today, 11:26 AM
          0 responses
          1 view
          0 likes
          Last Post Mupulen
          by Mupulen
           
          Started by Sparkyboy, Today, 10:57 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by TheMarlin801, 10-13-2020, 01:40 AM
          21 responses
          3,917 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Working...
          X