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 funk10101, Today, 09:43 PM
    0 responses
    6 views
    0 likes
    Last Post funk10101  
    Started by pkefal, 04-11-2024, 07:39 AM
    11 responses
    37 views
    0 likes
    Last Post jeronymite  
    Started by bill2023, Yesterday, 08:51 AM
    8 responses
    44 views
    0 likes
    Last Post bill2023  
    Started by yertle, Today, 08:38 AM
    6 responses
    26 views
    0 likes
    Last Post ryjoga
    by ryjoga
     
    Started by algospoke, Yesterday, 06:40 PM
    2 responses
    24 views
    0 likes
    Last Post algospoke  
    Working...
    X