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

Nulling Canceled Orders Unamanged

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

    Nulling Canceled Orders Unamanged

    I would like to null canceled orders while using unmanaged approach. In the templates provided, it shows orders being nullified individually by using their name

    example
    PHP Code:
                    if(targetShort_Unmanaged != null && targetShort_Unmanaged == order)
                    {
                    
                        if(
    order.OrderState  == OrderState.Cancelled && order.Filled == )
                        {
                            
    targetShort_Unmanaged null;
                        }
                    } 
    I would rather have it done automatically without having to specify each order type. Would the code below work for this

    PHP Code:
                        List<stringOrdersToNull = new List<string>();
                    
                        foreach(
    Order o in Orders)
                        {
                            if( 
    != null && o.OrderState == OrderState.Cancelled && order.Filled == )
                            {
                                
    OrdersToNull.Add(order.Name);
                            }

                        }
                        
                        for(
    int i =0OrdersToNull.Counti++)
                            {
                            
    OrdersToNull[i] = null;    
                            } 
    Also I have one more question, aside for it being just a reference, why would you ever want to nullify all SL and TP trades if one of them are canceled. I am just tying to understand the logic.

    Also, just because you set the order objects to null doesn't cancel the orders right? Wouldnt you need to use "CancelOrder(Order);" to cancel your protective orders?


    The below code is part of the unmanaged template.

    PHP Code:
                //sets all targets and stops to null if one of them is canceled
                //PLEASE NOTE: setting IOrders to null ***DOES NOT*** cancel them
                
    if ((targetLong != null && targetLong == order)
                    ||(
    stopLossLong != null && stopLossLong == order)
                    ||(
    targetShort != null && targetShort == order)
                    ||(
    stopLossShort != null && stopLossShort == order)
                    )
                {  
                    if (
    order.OrderState == OrderState.Cancelled && order.Filled == 0)
                    {
                        
    targetLong stopLossLong targetShort stopLossShort null;
                    }
                } 
    Last edited by cutzpr; 09-17-2018, 10:55 AM.

    #2
    Hello cutzpr,

    Thank you for the note.

    That looks like it will work fine. The context here is important i.e. where the code is being placed specifically will determine the outcome. Test this out on the Sim101 account and see if you get the expected results. You may turn on Trace Orders to get info about orders through the NinjaScript output window:



    Please let me know if I can assist further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_ChrisL,

      Sorry I edited my first post and added a question. Could you please take a look. thank you

      Comment


        #4
        Hello cutzpr,

        Thanks for the follow up.

        Nulling an Order object will not cancel it. You will need to use CancelOrder on your Stop or Target if one of them is canceled to get the "OCO" functionality. Only after the orders have reached the Canceled state should you nullify the Order object.

        Please let me know if I can assist further.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mestor, 03-10-2023, 01:50 AM
        16 responses
        388 views
        0 likes
        Last Post z.franck  
        Started by rtwave, 04-12-2024, 09:30 AM
        4 responses
        31 views
        0 likes
        Last Post rtwave
        by rtwave
         
        Started by yertle, Yesterday, 08:38 AM
        7 responses
        29 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by bmartz, 03-12-2024, 06:12 AM
        2 responses
        22 views
        0 likes
        Last Post bmartz
        by bmartz
         
        Started by funk10101, Today, 12:02 AM
        0 responses
        7 views
        0 likes
        Last Post funk10101  
        Working...
        X