• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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:

    https://ninjatrader.com/support/help...aceorders2.htm

    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 Ilpropio, Yesterday, 09:45 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_EricB  
        Started by sgordet, Yesterday, 10:31 PM
        1 response
        2 views
        0 likes
        Last Post NinjaTrader_EricB  
        Started by Revan, Yesterday, 05:44 PM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_Marco  
        Started by superg3, Yesterday, 07:57 PM
        0 responses
        4 views
        0 likes
        Last Post superg3
        by superg3
         
        Started by Longhornmark, Yesterday, 07:06 AM
        5 responses
        36 views
        0 likes
        Last Post nkhoi
        by nkhoi
         
        Working...
        X