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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    93 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    138 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    123 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    73 views
    0 likes
    Last Post PaulMohn  
    Working...
    X