Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit on session close bug?

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

    Exit on session close bug?

    Hello!

    I think NT8 b8 has a bug with exit on session close. It doesn't raise OnExecutionUpdate event for stop and target orders though they are closed together with the position. So the code:
    Code:
    if ((stopOrder != null && stopOrder == execution.Order) || (targetOrder != null && targetOrder == execution.Order))
    {
        if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
        {
            stopOrder = null;
            targetOrder = null;
        }
    }
    does not work, and 'stopOrder' and 'targetOrder' aren't nulled.

    Could you check that please?

    #2
    Hello quicktrick,

    OnExecutionUpdate is called when an order fills and not when an order is cancelled.

    If the stop loss and profit target are being cancelled this will not trigger OnExecution.

    The Exit on close will send an order named 'Exit on session close' to exit any open position and then cancel any working orders such as a stop loss or profit target.

    Can you clarify what you are expecting? Are you expecting that the profit target or stop loss will will fill at the same time the 'Exit on session close' order is submitted?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      I took that code from NT8's reference sample "Strategy: Using OnOrderUpdate() and OnExecution() methods to submit protective orders".

      I need my stop and target Order variables to be nulled after 'Exit on session close' the same way they are nulled after target or stop is reached. How can I do that?
      Last edited by quicktrick; 01-11-2016, 10:38 AM.

      Comment


        #4
        Hello quicktrick,

        When an order is cancelled this will trigger OnOrderUpdate and will have a Order.OrderState equal to OrderState.Cancelled.

        So when the order is cancelled you can detect this and set the Order handle to null.

        http://ninjatrader.com/support/helpG...rderupdate.htm
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you Chelsea, it works!

          I think you should modify your reference sample "Strategy: Using OnOrderUpdate() and OnExecution() methods to submit protective orders" by adding the code for checking the cancel of stop and target orders after 'Exit on session close', somehow like this:

          Code:
                  protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, 
                      double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
                  {
                      // Handle entry orders here. The entryOrder object allows us to identify that the order that is calling the OnOrderUpdate() method is the entry order.
                      if (entryOrder != null && entryOrder == order)
                      {
                          // Reset the entryOrder object to null if order was cancelled without any fill
                          if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                              entryOrder = null;
                      }
          
                      // Reset our stop order and target orders' Order objects after our position is closed on 'Exit on session close'.
                      if ((stopOrder != null && stopOrder == order) || (targetOrder != null && targetOrder == order))
                      {
                          if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                          {
                              stopOrder = null;
                              targetOrder = null;
                          }
                      }
                  }

          Comment


            #6
            Hello quicktrick,

            The stopLoss and profitTarget orders should not need to be set to null after an exit on close event for this strategy to function correctly.

            After the Exit on close, any open position will be exit and any working order will be cancelled. The stop loss and profit target will be resubmitted and the Order objects for these saved to handles the moment the new entry order fills. In this way should code be added to reset these variables, this would be unnecessary code according to the logic of how the script works.

            If you would like, I could make you a separate example of resetting these variables when the Exit on close is triggered.

            Would you like me to create an example script for you that demonstrates setting these variables to null when the Exit on close order fills or when the stop loss or profit target are cancelled?

            However, for the existing script, this would be unnecessary code for what is being demonstrated in the script.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Chelsea,

              You certainly know that when you develop strategies, you build a lot of other logic that relies on the existence or non-existence of stop/target orders to move them to other levels if needed. So you need their variables to be in compliance with the real conditions.

              I don't need any more examples, thank you. But I think those examples would be useful to other people, so they don't ask the same questions I did.

              Thanks again for your help!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by wzgy0920, 04-20-2024, 06:09 PM
              2 responses
              26 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 02-22-2024, 01:11 AM
              5 responses
              32 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, Yesterday, 09:53 PM
              2 responses
              49 views
              0 likes
              Last Post wzgy0920  
              Started by Kensonprib, 04-28-2021, 10:11 AM
              5 responses
              192 views
              0 likes
              Last Post Hasadafa  
              Started by GussJ, 03-04-2020, 03:11 PM
              11 responses
              3,234 views
              0 likes
              Last Post xiinteractive  
              Working...
              X