Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position entered with no stop

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

    Position entered with no stop

    My strategy entered a position without also entering stop or target orders. I had realtime error handling set to take no action. I took a look at the log and there was no rejection or error. I had 2 other trades that executed normally with stops and targets. I recently switched to realtime error take no action and added the if statement for the orderstate.rejected into the IOrder method. So Im thinking that the order.OrderState == OrderState.Rejected somehow caused the order to be filled with no stop or target. Is this possible with the code below?

    Code:
    protected override void OnOrderUpdate(IOrder order)
            {
                if (entryOrder != null && entryOrder == order)
                {    
                    if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                    {
                        entryOrder = null;
                    }
                    if (order.OrderState == OrderState.Rejected)
                    {
                        entryOrder = null;
                    }
                }
            }
            
            protected override void OnExecution(IExecution execution)
            {
                /* We advise monitoring OnExecution to trigger submission of stop/target orders instead of OnOrderUpdate() since OnExecution() is called after OnOrderUpdate()
                which ensures your strategy has received the execution which is used for internal signal tracking. */
                if (entryOrder != null && entryOrder == execution.Order)
                {
                    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                    {
                        // Stop-Loss order right above last high bar, 2* .01 tick size = 2 ticks above high
                        stopOrder     = ExitShortStop(0, true, execution.Order.Filled, High[1]+2.0 * TickSize, "Stop", "EnterShort");
                        
                        // Target order 90 ticks below our entry price
                        targetOrder = ExitShortLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - (target *TickSize), "Target", "EnterShort");
                        
                        // Stop-Loss order below last low before execution. 2* .01 tick size = 2 ticks under low
                        stopOrder2 = ExitLongStop(0, true, execution.Order.Filled, Low[1]-4.00 * TickSize, "Stop", "EnterLong");
                        
                        // Target order 50 ticks above our entry price
                        targetOrder2 = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + (target * TickSize), "Target", "EnterLong");
                        
                        // Resets the entryOrder object to null after the order has been filled
                        if (execution.Order.OrderState != OrderState.PartFilled)
                        {
                            entryOrder     = null;
                        }
                    }
                }
                // Reset our stop order and target orders' IOrder objects after our position is closed.
                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;
                    }
                }
                if ((stopOrder2 != null && stopOrder2 == execution.Order) || (targetOrder2 != null && targetOrder2 == execution.Order))
                {
                    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
                    {
                        stopOrder2 = null;
                        targetOrder2 = null;
                    }
                }
            }

    #2
    Hello superhaze421,

    Thank you for your post.

    I see nothing in the code that would cause this for one entry but no another. Please enable TraceOrders in your strategy and run the strategy again with the Output window open (Tools > Output): http://www.ninjatrader.com/support/f...ead.php?t=3627

    Comment


      #3
      So is there any need to check for order.Filled ==0 in the order rejection if() statement, the one above it for cancelled orders uses one.

      Comment


        #4
        Hello superhaze421,

        You could just use the following:
        Code:
                        if (order.OrderState == OrderState.Cancelled && order.Filled == 0 || order.OrderState == OrderState.Rejected)
                        {
                            entryOrder = null;
                        }
        Either way it should work.

        Comment


          #5
          ok but the order.Filled==0 only applies to the orderstate.cancelled, do I also need to add it after the orderstate.rejected check.

          Like this

          Code:
           if (order.OrderState == OrderState.Cancelled && order.Filled == 0 || order.OrderState == OrderState.Rejected && order.Filled == 0)
                          {
                              entryOrder = null;
                          }

          Comment


            #6
            Hello superhaze421,

            No, that would not be needed.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            648 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            573 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X