Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order ignored: Stop price '12364.75' near the bar stamped '2020-12-09 7:50:00 pm" ?!?

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

    Order ignored: Stop price '12364.75' near the bar stamped '2020-12-09 7:50:00 pm" ?!?

    Hello Support,

    I have been getting this error in the NT LOG running a strategy against NQ 03-21, using Strategy Analyzer

    Strategy 'cscCTMacdv02/-1': An order has been ignored since the stop price ‘12364.75’ near the bar stamped ‘2020-12-09 7:50:00 PM’ is invalid based on the price range of the bar. This is an invalid order and subsequent orders may also be ignored.

    The logic around the ExitShortStopMarket, where dblSL is the stop price:

    //Long
    if (dblSL < Position.AveragePrice
    && dblSL < stopOrder.StopPrice
    && Instrument.MasterInstrument.Compare(dblSL, Low[0]) == -1
    && Instrument.MasterInstrument.Compare(dblSL, GetCurrentAsk()) == -1
    && Instrument.MasterInstrument.Compare(dblSL, GetCurrentBid()) == -1)
    stopOrder = ExitLongStopMarket(0, true, Position.Quantity, dblSL, "MyStop", "MyEntry");


    // Short
    if (dblSL > Position.AveragePrice
    && dblSL > stopOrder.StopPrice
    && dblSL > High[0]
    && Instrument.MasterInstrument.Compare(dblSL, High[0]) == 1
    && Instrument.MasterInstrument.Compare(dblSL, GetCurrentAsk()) == 1
    && Instrument.MasterInstrument.Compare(dblSL, GetCurrentBid()) == 1)
    stopOrder = ExitShortStopMarket(0, true, Position.Quantity, dblSL, "MyStop", "MyEntry");

    Can you please tell me what exactly this NT error message is trying to say or a link to somewhere in Help ?

    Thank you

    #2
    Hello rayko,

    Thank you for your post.

    The message is letting you know that a stop order was ignored because the strategy submitted the order to an invalid price level. Buy stop orders must be placed above the current ask price. Sell stop orders must be placed below the current ask price.

    When the order is submitted, is the stop price parameter greater than the GetCurrentAsk() for a buy stop order? Or, is the stop price parameter less than the GetCurrentAsk() for a sell stop order?

    I would recommend you add prints to the strategy to determine why the stop order is being ignored. One line above where the stop order is placed, print the GetCurrentAsk() and print the price being submitted to the order method.

    Below is a link to a forum post that demonstrates using prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    Please see the help guide documentation below for more information about GetCurrentAsk().
    https://ninjatrader.com/support/help...currentask.htm

    We should also note that there is no intrabar movement with historical processing. If the strategy is using Standard Order Fill Resolution, it will create "virtual bars" based on the OHLC of the next bar to simulate how market data moved and then fill the order. If you use Order Fill Resolution set to High and use a 1 tick data series, the order will be filled with intrabar granularity because it is submitted to the single tick data series. The cases where this error is seen could be resolved using Order Fill Resolution set to High or adding a single tick data series to the strategy and submitting orders to that strategy.

    Backtesting with intrabar granularity - https://ninjatrader.com/support/help...ipt_strate.htm

    More information on Historical Fill Processing can be found here - https://ninjatrader.com/support/help...ical_fill_.htm

    Below is a video demonstration showing the debugging steps that would be taken to analyze how the error was received.

    Demo - https://drive.google.com/file/d/14pT...w?usp=drivesdk

    You could find the script used to test this on the this forum thread: https://ninjatrader.com/support/foru...82#post1104682

    Let us know if you have any questions.
    Last edited by NinjaTrader_BrandonH; 01-23-2023, 10:40 AM.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hello Brandon

      Thanks for all the info you provided.

      As you suggested, I've changed the code to print OHLC, bid, ask, and trace orders

      protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
      {
      if (stopOrder == null
      && Instrument.MasterInstrument.Compare(dblSL, Low[0]) == -1
      && Instrument.MasterInstrument.Compare(dblSL, GetCurrentAsk()) == -1
      && Instrument.MasterInstrument.Compare(dblSL, GetCurrentBid()) == -1)
      {
      stopOrder = ExitLongStopMarket(0, true, Position.Quantity, dblSL, "MyStop", "MyEntry");

      if (stopOrder == null)
      DumpVars("Entry Long Stop is NULL", dblSL);
      }
      }

      private void DumpVars(string strMsg, double dblSL)
      {
      Print("DumpVars.." + Bars.ToChartString() + "\t" + Time[0].ToString("MM/dd/yyyy\tHH:mm:ss")
      + " SL=" + dblSL
      + " Ask=" + GetCurrentAsk()
      + " Bid=" + GetCurrentBid()
      + " Open=" + Open[0]
      + " High=" + High[0]
      + " Low=" + Low[0]
      + " Close=" + Close[0]
      + " stopOrder=" + (stopOrder == null ? "null" : stopOrder.ToString())
      + "..." + strMsg

      );
      }
      protected override void OnOrderTrace(DateTime timestamp, string message)
      {
      DateTime date1 = new DateTime(2020, 12, 10, 7, 10, 0);
      if (Time[0] == date1)
      {
      // The below print would give us the default tracing
      Print(string.Format("OrdTrace.. {0} {1}", timestamp, message));
      }

      // The extended example would also include the instrument fullname from our primary bars object
      //if (BarsArray[0] != null)
      // Print(string.Format("{0} {1} {2}", timestamp, message, BarsArray[0].Instrument.FullName));
      }


      I then ran in System Analyzer batch, using YM 03-21 so its easier to read prices on the log.

      When run at Standard Order Fill Resolution, the trace log shows
      OrdTrace.. 2020-12-10 7:10:00 AM Strategy 'cscCTMacdv02/-1': Entered internal SubmitOrderManaged() method at 2020-12-10 7:10:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='MyEntry' FromEntrySignal=''
      OrdTrace.. 2020-12-10 7:10:00 AM Strategy 'cscCTMacdv02/-1': Entered internal SubmitOrderManaged() method at 2020-12-10 7:10:00 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=30000 SignalName='MyStop' FromEntrySignal='MyEntry'
      Strategy 'cscCTMacdv02/-1': An order has been ignored since the stop price ‘30000’ near the bar stamped ‘2020-12-10 7:10:00 AM’ is invalid based on the price range of the bar. This is an invalid order and subsequent orders may also be ignored.
      OrdTrace.. 2020-12-10 7:10:00 AM Strategy 'cscCTMacdv02/-1': Ignored SubmitOrderManaged() method at 2020-12-10 7:10:00 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=30000 SignalName='MyStop' FromEntrySignal='MyEntry' Reason='Invalid order price, please see log tab'
      DumpVars..YM 03-21 (10 Minute) 12-10-2020 07:10:00 SL=30000 Ask=30005 Bid=30005 Open=30012 High=30012 Low=30002 Close=30005 stopOrder=null...Entry Long Stop is NULL
      OrdTrace.. 2020-12-10 7:10:00 AM Strategy 'cscCTMacdv02/-1': Entered internal SubmitOrderManaged() method at 2020-12-10 7:10:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=30020 StopPrice=0 SignalName='MyTarget' FromEntrySignal='MyEntry'


      When run at High Resolution and 1-Tick granularity, the trace log shows
      OrdTrace.. 2020-12-10 7:10:00 AM Strategy 'cscCTMacdv02/-1': Entered internal SubmitOrderManaged() method at 2020-12-10 7:10:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='MyEntry' FromEntrySignal=''
      OrdTrace.. 2020-12-10 7:10:00 AM Strategy 'cscCTMacdv02/-1': Entered internal SubmitOrderManaged() method at 2020-12-10 7:10:00 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=30000 SignalName='MyStop' FromEntrySignal='MyEntry'
      Strategy 'cscCTMacdv02/-1': An order has been ignored since the stop price ‘30000’ near the bar stamped ‘2020-12-10 7:10:00 AM’ is invalid based on the price range of the bar. This is an invalid order and subsequent orders may also be ignored.
      OrdTrace.. 2020-12-10 7:10:00 AM Strategy 'cscCTMacdv02/-1': Ignored SubmitOrderManaged() method at 2020-12-10 7:10:00 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=30000 SignalName='MyStop' FromEntrySignal='MyEntry' Reason='Invalid order price, please see log tab'
      DumpVars..YM 03-21 (10 Minute) 12-10-2020 07:10:00 SL=30000 Ask=30005 Bid=30005 Open=30012 High=30012 Low=30002 Close=30005 stopOrder=null...Entry Long Stop is NULL
      OrdTrace.. 2020-12-10 7:10:00 AM Strategy 'cscCTMacdv02/-1': Entered internal SubmitOrderManaged() method at 2020-12-10 7:10:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=30020 StopPrice=0 SignalName='MyTarget' FromEntrySignal='MyEntry'



      As you can see, in both cases SL=30000 is less than Ask=30005 Bid=30005 and not an error, but is Correct and valid. Right ? I don't get it.

      Can you please let know what I missing, I don't see the error since StopPrice is less than GetCurrentAsk().

      Thank you.


      Comment


        #4
        Hello rayko,

        Thank you for that information.

        Please send the OHLC output information for the 7:20 AM bar so we may further investigate this matter.

        Thanks in advance, I look forward to resolving this.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Hello Brandon,

          I inserted this additional code into OnBarUpdate()
          DateTime date1 = new DateTime(2020, 12, 10, 7, 20, 0);
          if (Time[0] == date1)
          {
          double dblSL = cscMACDTrendtic1.TRADE_Stoploss[0];
          DumpVars("At Time=" + Time[0].ToString(), dblSL);
          }


          When run at Standard Order Fill Resolution, the trace log shows
          OrdTrace.. 2020-12-10 7:10:00 AM Strategy 'cscCTMacdv02/-1': Entered internal SubmitOrderManaged() method at 2020-12-10 7:10:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='MyEntry' FromEntrySignal=''
          OrdTrace.. 2020-12-10 7:10:00 AM Strategy 'cscCTMacdv02/-1': Entered internal SubmitOrderManaged() method at 2020-12-10 7:10:00 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=30000 SignalName='MyStop' FromEntrySignal='MyEntry'
          Strategy 'cscCTMacdv02/-1': An order has been ignored since the stop price ‘30000’ near the bar stamped ‘2020-12-10 7:10:00 AM’ is invalid based on the price range of the bar. This is an invalid order and subsequent orders may also be ignored.
          OrdTrace.. 2020-12-10 7:10:00 AM Strategy 'cscCTMacdv02/-1': Ignored SubmitOrderManaged() method at 2020-12-10 7:10:00 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=30000 SignalName='MyStop' FromEntrySignal='MyEntry' Reason='Invalid order price, please see log tab'
          DumpVars..YM 03-21 (10 Minute) 12-10-2020 07:10:00 SL=30000 Ask=30005 Bid=30005 Open=30012 High=30012 Low=30002 Close=30005 stopOrder=null...Entry Long Stop is NULL
          OrdTrace.. 2020-12-10 7:10:00 AM Strategy 'cscCTMacdv02/-1': Entered internal SubmitOrderManaged() method at 2020-12-10 7:10:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=30020 StopPrice=0 SignalName='MyTarget' FromEntrySignal='MyEntry'
          DumpVars..YM 03-21 (10 Minute) 12-10-2020 07:20:00 SL=0 Ask=29974 Bid=29974 Open=29997 High=29997 Low=29974 Close=29974 stopOrder=null...At Time=2020-12-10 7:20:00 AM


          When run at High Resolution and 1-Tick granularity, the trace log shows
          OrdTrace.. 2020-12-10 7:10:00 AM Strategy 'cscCTMacdv02/-1': Entered internal SubmitOrderManaged() method at 2020-12-10 7:10:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='MyEntry' FromEntrySignal=''
          OrdTrace.. 2020-12-10 7:10:00 AM Strategy 'cscCTMacdv02/-1': Entered internal SubmitOrderManaged() method at 2020-12-10 7:10:00 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=30000 SignalName='MyStop' FromEntrySignal='MyEntry'
          Strategy 'cscCTMacdv02/-1': An order has been ignored since the stop price ‘30000’ near the bar stamped ‘2020-12-10 7:10:00 AM’ is invalid based on the price range of the bar. This is an invalid order and subsequent orders may also be ignored.
          OrdTrace.. 2020-12-10 7:10:00 AM Strategy 'cscCTMacdv02/-1': Ignored SubmitOrderManaged() method at 2020-12-10 7:10:00 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=30000 SignalName='MyStop' FromEntrySignal='MyEntry' Reason='Invalid order price, please see log tab'
          DumpVars..YM 03-21 (10 Minute) 12-10-2020 07:10:00 SL=30000 Ask=30005 Bid=30005 Open=30012 High=30012 Low=30002 Close=30005 stopOrder=null...Entry Long Stop is NULL
          OrdTrace.. 2020-12-10 7:10:00 AM Strategy 'cscCTMacdv02/-1': Entered internal SubmitOrderManaged() method at 2020-12-10 7:10:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=30020 StopPrice=0 SignalName='MyTarget' FromEntrySignal='MyEntry'
          DumpVars..YM 03-21 (10 Minute) 12-10-2020 07:20:00 SL=0 Ask=29974 Bid=29974 Open=29997 High=29997 Low=29974 Close=29974 stopOrder=null...At Time=2020-12-10 7:20:00 AM


          Please let me know.

          Thank you

          Comment


            #6
            Hello rayko,

            Thank you for that information.

            According to the output information you provided, it seems that the order is being placed at the close of the 7:10 AM bar at a price value of 30,000. Since the order is being placed on the close of the 7:10 AM bar, that would make the 7:20 AM bar the actual submission bar for that order. The first tick of the 7:20 AM bar is at a price value of 29,997 (the Open). The stop order submitted at 30,000 when the Open of the 7:20 AM bar is 29,997. The order is being ignored since it is being submitted at a price value above the Open price of the 7:20 AM bar. For the stop order to successfully submit it would need to be submitted below the current Ask/Bid price.

            Please let us know if we may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Hello Brandon,

              I looked into the final chart and saw what you mean. There is a huge gap between the 7:10 close and 7:20 open that eclipsed the Stoploss price, leaving the position naked.

              To mitigate the problem, I changed the code to immediately Bail out of the position since the gap is against trade and minimize loss to just commission.

              I've uploaded Chart picture of the chart.

              Thanks for your help!
              Attached Files

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by helpwanted, Today, 03:06 AM
              0 responses
              2 views
              0 likes
              Last Post helpwanted  
              Started by Brevo, Today, 01:45 AM
              0 responses
              6 views
              0 likes
              Last Post Brevo
              by Brevo
               
              Started by aussugardefender, Today, 01:07 AM
              0 responses
              5 views
              0 likes
              Last Post aussugardefender  
              Started by pvincent, 06-23-2022, 12:53 PM
              14 responses
              242 views
              0 likes
              Last Post Nyman
              by Nyman
               
              Started by TraderG23, 12-08-2023, 07:56 AM
              9 responses
              384 views
              1 like
              Last Post Gavini
              by Gavini
               
              Working...
              X