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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    54 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    25 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    17 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    23 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    24 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X