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

closing open orders on terrmination

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

    closing open orders on terrmination

    Hi

    I am using the bellow code.
    and get an error of object reference is not set to an instance of an object

    what am I not defining correctly ? do I need to specifically define the account ?


    Code:
    else if (State == State.Terminated)
    {
    foreach (Order order in Account.Orders)
    {
    if ( Position.MarketPosition == MarketPosition.Flat) CancelOrder(order);
    }
    }
    also trying :
    Code:
    for( int i = 0; i < Account.Orders.Count; i++ )
    {
    if ( Position.MarketPosition == MarketPosition.Flat) CancelOrder(Account.Orders[i]);
    }
    thanks
    Last edited by dadarara; 08-05-2020, 07:28 AM.

    #2
    Hello dadarara,

    Thank you for your post.

    I would not suggest checking PositionAccount when attempting to cancel all orders on the account as you would be canceling all orders, not just those of the instrument the strategy is applied to.

    If you want to cancel all orders on the account you could do something like the following, this will also work in State.Terminated.

    if (Account != null)
    foreach (Order actOrdr in Account.Orders)
    {
    Account.Cancel(new[] { actOrdr });
    }


    If you are trying to have all strategy orders canceled when disabling the strategy, I would instead suggest checking the Cancel entry orders when a strategy is disabled and the Cancel exit orders when a strategy is disabled options in the Control Center's Tools > Options > Strategies menu

    Here are a few Help Guide links for more information

    Account class - https://ninjatrader.com/support/help...ount_class.htm


    NinjaScript Properties - https://ninjatrader.com/support/help...riptProperties

    Please let us know if we may further assist.
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by andrewtrades, Today, 04:57 PM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by chbruno, Today, 04:10 PM
    0 responses
    6 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by josh18955, 03-25-2023, 11:16 AM
    6 responses
    436 views
    0 likes
    Last Post Delerium  
    Started by FAQtrader, Today, 03:35 PM
    0 responses
    7 views
    0 likes
    Last Post FAQtrader  
    Started by rocketman7, Today, 09:41 AM
    5 responses
    19 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X