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

Stop order rejection

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

    Stop order rejection

    Hi,
    Im using EnterShortStop() and EnterLongStop to enter positions. Sometimes when the market is moving fast my orders end up getting rejected even though it checks the bid or ask and the last before submitting the order.

    code for checking the ask, last, and if its still in the same bar for long entry
    Code:
    if(High[2]+.02 > GetCurrentAsk()&& High[2]+.02 > High[0] && High[2]+.02 > Close[0])
                        {
                    entryOrder = EnterLongStop(High[2]+.02, "EnterLong");
                        }
    Same for getting short
    Code:
    if(Low[2]-.02 < GetCurrentBid()&& Low[2]-.02 < Low[0] && Low[2]-.02 < Close[0])
                        {
                    entryOrder = EnterShortStop(Low[2]-.02, "EnterShort");
                        }
    How would i go about handling the error and not getting it rejected and disabling the strategy? I'm using the NT managed approach to handle errors.
    Also im using OnOrderUpdate(IOrder order) and OnExecution(IExecution execution) for the order handling/ stops and targets.
    Last edited by superhaze421; 12-09-2014, 11:33 AM.

    #2
    Hello superhaze421,

    Thank you for your post.

    Please send me your log and trace files for today so that I may look into what occurred. You can do this by going to the Control Center-> Help-> Mail to Platform Support. Ensure you place this thread in the subject line: 'http://www.ninjatrader.com/support/forum/showthread.php?t=70680'
    And please put 'ATTN: Patrick - 1212990' in the body of the e-mail.

    Comment


      #3
      Hello superhaze421,

      Thank you for your patience and for sending in those files.

      This can occur during fast market moves, if the order is sent to a price that matches your condition and then the market moves away from the price in a direction that would cause it to be invalid we would see these rejections.

      If you are not running CalculateOnBarClose = false, you can set it to false to make sure the calculations are intra-bar and not waiting for the end of the bar.

      Otherwise, these race conditions can occur and you may wish to move the stop further from the market or use a market order for entry.

      Comment


        #4
        If I use RealtimeErrorHandling.TakeNoAction to avoid the strategy being disabled and i get a order rejection from the exchange, since im using the OnExecution(IExecution execution) below for stop and target orders, is there any need to worry about pending orders not being cancelled? OnExecutions only submits the stop and target if the position is filled, correct? I just want to make sure there are no positions without stops or pending orders floating around somewhere.

        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)
                {
                    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))
                        {
                            stopOrder     = ExitShortStop(0, true, execution.Order.Filled, High[1]+(2.0 * TickSize), "Stop", "EnterShort");
                            
                            targetOrder = ExitShortLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - (target *TickSize), "Target", "EnterShort");
                            
                            stopOrder2 = ExitLongStop(0, true, execution.Order.Filled, Low[1]-(2.00 * TickSize), "Stop", "EnterLong");
                            
                            targetOrder2 = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + (target * TickSize), "Target", "EnterLong");
                            
                            if (execution.Order.OrderState != OrderState.PartFilled)
                            {
                                entryOrder     = null;
                            }
                        }
                    }
                    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;
                        }
                    }
                }

        Comment


          #5
          Hello superhaze421,

          Thank you for your response.

          As you have set your OnExecution() method it would not submit the exit orders if the entry did not fill.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by sofortune, 05-18-2024, 11:48 AM
          2 responses
          32 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by Zach55, 02-19-2024, 07:22 PM
          2 responses
          65 views
          0 likes
          Last Post lbadisa1  
          Started by JGriff5646, Yesterday, 05:47 PM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by AlphaOptions, 06-18-2013, 08:24 AM
          9 responses
          2,203 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by ttrader23, Yesterday, 09:33 AM
          3 responses
          29 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X