Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unable to change order

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

    Unable to change order

    I am entering in a trade this way: https://ibb.co/99m2vn5
    Once the entries get filled, I am setting the StopOrder: https://ibb.co/XynZgCN
    On every bar, I am changing the StopOrder: https://ibb.co/vhVH2dS
    On every bar, I am checking if StopOrder == null. if yes, then close the order: https://ibb.co/D9pQNkh
    Now I am getting this error sometimes: https://ibb.co/MRn8m5V

    I think the problem is something like this: When the price is touching the stop order, its cancelling, but it is taking some time to do that. In the mean time strategy is trying to change the stop order. That's where the error is taking place. Is there a way to use Advanced Order Handling to check if a trade is pending cancel order? so that instead of checking for StopOrder == null, i can check if StopOrder is pending for cancel or not? Or some other solution. Thank you



    #2
    Hello fawzanalim,

    Thanks for your post.

    If you are keeping Order objects updated in OnOrderUpdate, you could check if YourOrder.OrderState != OrderState.CancelSubmitted or YourOrder.OrderState != OrderState.CancelPending or YourOrder.OrderState != OrderState.Cancelled before trying to modify the order. Although the Order object should be set to null after it is cancelled, so the Cancelled check should not be necessary.

    Something else to consider would be to have the strategy use RealtimeErrorHandling.IgnoreAllErrors so it does not disable with order errors like this. You could then check for the ErrorCode of the error parameter in OnOrderUpdate to see if it is ErrorCode.UnableToChangeOrder to identify the order error. If all is well, you wouldn't have to take additional actions, just let the strategy keep going. If there is another order error or rejection that you want to disable for, you can call CloseStrategy().

    I gave some commentary on handling order rejections in the threads below. Similar ideas can be considered for handling order errors with RealtimeErrorHandling.IgnoreAllErrors.

    Previous threads:

    https://ninjatrader.com/support/foru...get-was-filled

    https://ninjatrader.com/support/foru...ct#post1167395

    Documentation links:

    RealtimeErrorHandling - https://ninjatrader.com/support/help...orhandling.htm

    OnOrderUpdate - https://ninjatrader.com/support/help...rderupdate.htm

    CloseStrategy() - https://ninjatrader.com/support/help...sestrategy.htm

    Let us know if you have any additional questions.
    Last edited by NinjaTrader_Jim; 08-26-2021, 11:16 AM.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    93 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    138 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    123 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    73 views
    0 likes
    Last Post PaulMohn  
    Working...
    X