Announcement

Collapse
No announcement yet.

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, 06: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 slimoriginus, Today, 10:07 PM
    0 responses
    1 view
    0 likes
    Last Post slimoriginus  
    Started by slimoriginus, Today, 10:05 PM
    0 responses
    1 view
    0 likes
    Last Post slimoriginus  
    Started by KevinWalker, Today, 07:48 PM
    0 responses
    6 views
    0 likes
    Last Post KevinWalker  
    Started by WaveAtElliot, Today, 05:11 PM
    1 response
    13 views
    1 like
    Last Post hdge4u
    by hdge4u
     
    Started by bosajin, Yesterday, 09:15 AM
    5 responses
    40 views
    0 likes
    Last Post NinjaTrader_Jim  
    Working...
    X