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

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.
    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Waxavi, Today, 02:10 AM
    0 responses
    3 views
    0 likes
    Last Post Waxavi
    by Waxavi
     
    Started by TradeForge, Today, 02:09 AM
    0 responses
    8 views
    0 likes
    Last Post TradeForge  
    Started by Waxavi, Today, 02:00 AM
    0 responses
    2 views
    0 likes
    Last Post Waxavi
    by Waxavi
     
    Started by elirion, Today, 01:36 AM
    0 responses
    4 views
    0 likes
    Last Post elirion
    by elirion
     
    Started by gentlebenthebear, Today, 01:30 AM
    0 responses
    4 views
    0 likes
    Last Post gentlebenthebear  
    Working...
    X