Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to use Cancel() from a different method

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

    How to use Cancel() from a different method

    I have a custom button that creates orders. I want to create another button that cancels all purple line pending orders. I cannot use CancelAllOrders() because I only want to cancel the purple pending orders. For example if I'm currently already in a positions with profit targets and stops, I do not want CancelAllOrders to cancel the exisiting profit targets and stops. I only want to cancel any purple pending orders.

    The code below successfully cancels the buyOrder immediately after it is placed. However if I place a.Cancel(new[] { buyOrder }); into a new method for a new button, it doesn't work.
    How can I reference the correct buyOrder in the new method?
    Alternatively, is it possible to loop through all existing purple pending orders and cancel them?

    Code:
    Order buyOrder = a.CreateOrder(Instrument, OrderAction.Buy, OrderType.StopLimit, TimeInForce.Day, quantitySelector.Value, high + .25, high + .25, string.Empty, "Entry", null);
    NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrategy("1", buyOrder);
    
    Print(buyOrder.Id);
    
    a.Cancel(new[] { buyOrder });

    #2
    Hello backtester831,

    Thank you for your post.

    Would you be able to provide a more complete sample of what you're trying including the button event and variables being used? Also, I'm unsure what you mean by "purple pending orders" - do you mean Stop Limit orders? Those are colored violet when displayed in Chart Trader.

    Thanks in advance; I look forward to assisting you further.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    42 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    29 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    46 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    38 views
    0 likes
    Last Post CarlTrading  
    Working...
    X