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 maybeimnotrader, Today, 05:46 PM
        0 responses
        6 views
        0 likes
        Last Post maybeimnotrader  
        Started by quantismo, Today, 05:13 PM
        0 responses
        6 views
        0 likes
        Last Post quantismo  
        Started by AttiM, 02-14-2024, 05:20 PM
        8 responses
        166 views
        0 likes
        Last Post jeronymite  
        Started by cre8able, Today, 04:22 PM
        0 responses
        8 views
        0 likes
        Last Post cre8able  
        Started by RichStudent, Today, 04:21 PM
        0 responses
        5 views
        0 likes
        Last Post RichStudent  
        Working...
        X