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

Limit Order not getting cancelled.

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

    Limit Order not getting cancelled.

    I have a limit order which gets submitted in on order update routine if it meets certain conditions.
    if((error == ErrorCode.OrderRejected) || (orderState == OrderState.Rejected))
    {
    msg = string.Format("Order status = {0}, Market Postiion = {1}, order name = {2}, order signal = {3}", orderState, Position.MarketPosition, order.Name, order.FromEntrySignal);
    Print(msg);
    if(order.Name == "LongDumpling")
    {
    msg = string.Format("Market position is Flag and signal is Long Dumpling with entry of = {0} and current bar at {1}", Entry_Price_L, CurrentBars[1]);
    Limit_order = EnterLongLimit(3, Entry_Price_L, "LongDumpling");
    limit_bar_number = CurrentBars[1];
    }
    else if(order.Name == "ShortDumpling")
    {
    msg = string.Format("Market position is Flag and signal is Short Dumpling with entry of = {0} and current bar at {1}", Entry_Price_L, CurrentBars[1]);
    Limit_order = EnterShortLimit(3, Entry_Price_S, "ShortDumpling");
    limit_bar_number = CurrentBars[1];
    }
    Print(msg);
    }
    }

    i want to cancel the order after 1 bar. So i call this routine on onbarupdate

    f(((CurrentBars[1] - limit_bar_number) >0) && (limit_bar_number != 0))
    {
    if((Limit_order.OrderState != OrderState.Filled) && (Limit_order.OrderState != OrderState.Cancelled) )
    {
    CancelOrder(Limit_order);
    msg = string.Format("Cancelling Limit Order, Position Flat and signal is Long Dumpling with entry of = {0} and current bar at {1}", CurrentBars[1] , limit_bar_number);
    Print(msg);

    }
    }
    }

    I can the the print below the cancel order however the Cancel routine does not appear to work.



    #2
    Hello sgkcfc,

    Is the order in a Working or Accepted OrderState?

    Print the <order>.OrderState before calling CancelOrder().

    Does TraceOrders have any information appearing in the Output window?
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by geotrades1, Today, 10:02 AM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by ender_wiggum, Today, 09:50 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by rajendrasubedi2023, Today, 09:50 AM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by bmartz, Today, 09:30 AM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by geddyisodin, Today, 05:20 AM
    3 responses
    26 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Working...
    X