Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Pending Cancel

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

    Order Pending Cancel

    I am attempting to cancel a pending order if it does not execute within my DM criteria at the current candle due to slippage or whatever the case may be. Can you help with this. I have the slippage set during the back test to get more precise outcomes as i know slippage can change on a per trade basis. I was thinking IO order was the way to go about it but i can't figure out how to code the pending order cancel if trade conditions change.

    if ( CrossAbove(DM(14).DiMinus, DM(14).DiPlus, 1))

    //////////////////Entry//////////////
    {entryOrder = EnterShortLimit(0, true, DefaultQuantity, Close[0] , "Short Limit");

    SetProfitTarget("Short Limit", CalculationMode.Percent, 5);
    ExitShort("", "Short Limit");
    }

    if(CrossAbove(DM(14).DiPlus, DM(14).DiMinus, 1)
    &&DM(14).DiPlus[6] > DM(14).DiMinus[6])
    {
    ExitShort("", "Short Limit");
    }

    protected override void OnOrderUpdate(IOrder order)
    {
    if ( entryOrder != OrderState.Filled
    &&DM(14).DiPlus[0] > DM(14).DiMinus[0])
    {
    CancelOrder(entryOrder);
    }
    }

    #2
    Hello NewCode,

    Thank you for your note.

    From the code sample provided its not clear what the issue is however I would suggest seeing the following links which provide samples of how to submit profit target and stop loss orders as well as how to cancel a working order.

    Default Strategy: Using OnOrderUpdate() and OnExecution() methods to submit protective orders

    The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


    Default Strategy: Using CancelOrder() method to cancel orders

    When using NinjaTrader's Enter() and Exit() methods, the default behavior is to automatically expire them at the end of a bar unless they are resubmitted to keep them alive. Sometimes you may want more flexibility in this behavior and wish to submit orders as live-until-cancelled. When orders are submitted as live-until


    If you still need additional help please upload the complete strategy along with the behavior you are seeing vs expected.

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X