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

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 DJ888, 04-16-2024, 06:09 PM
    6 responses
    18 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    1 view
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    6 views
    0 likes
    Last Post Javierw.ok  
    Started by timmbbo, Today, 08:59 AM
    2 responses
    10 views
    0 likes
    Last Post bltdavid  
    Started by alifarahani, Today, 09:40 AM
    6 responses
    41 views
    0 likes
    Last Post alifarahani  
    Working...
    X