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

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.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by JoMoon2024, Today, 06:56 AM
    0 responses
    6 views
    0 likes
    Last Post JoMoon2024  
    Started by Haiasi, 04-25-2024, 06:53 PM
    2 responses
    17 views
    0 likes
    Last Post Massinisa  
    Started by Creamers, Today, 05:32 AM
    0 responses
    6 views
    0 likes
    Last Post Creamers  
    Started by Segwin, 05-07-2018, 02:15 PM
    12 responses
    1,786 views
    0 likes
    Last Post Leafcutter  
    Started by poplagelu, Today, 05:00 AM
    0 responses
    3 views
    0 likes
    Last Post poplagelu  
    Working...
    X