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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    53 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    70 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X