Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Analyzer

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

    Strategy Analyzer

    Hi,

    I am trying to run my strategy through the Strategy Analyzer but it is ignoring some orders with the following error message:

    Strategy 'MOSTStrategy/-1': An order has been ignored since the stop price ‘1688’ near the bar stamped ‘05/03/2021 00:36:52’ is invalid based on the price range of the bar. This is an invalid order and subsequent orders may also be ignored.

    The Instrument is GC 04-21
    The OHLC of the entry bar (05/03/2021 00:35:39):

    O: 1687.5
    H: 1687.9
    L: 1687.2
    C: 1687.6

    The OHLC of the ordering bar (05/03/2021 00:36:52):

    O: 1687.7
    H: 1688.8
    L: 1687.7
    C: 1688.7

    Below is the debug trace for this order:

    Processing bar at 05/03/2021 00:36:52

    Placing Long order after close of bar = 05/03/2021 00:35:39
    Stop = 1686.8
    Entry = 1688
    Trigger(Stop) = 1688
    Breakeven = 1688.8
    Target = 1689
    Order Qty = 1
    Ask Price = 1687.9

    The order command is as follows:

    if (IsInStrategyAnalyzer)
    {
    if (Instrument.MasterInstrument.Compare(TriggerPrice , Bars.GetAsk(CurrentBar)) > 0)
    entryOrder = EnterLongStopLimit(0, true, OrderQty, EntryPrice, TriggerPrice, "EntryOrder");
    else
    entryOrder = EnterLongLimit(0, true, OrderQty, Bars.GetAsk(CurrentBar)+TickSize, "EntryOrder");
    }

    Can anyone tell me what this error means and why it is happening?
    MarkF60
    NinjaTrader Ecosystem Vendor - futureslivetradingrooom.com

    #2
    Hello MarkF60,

    With EnterLongStopLimit(0, true, OrderQty, EntryPrice, TriggerPrice, "EntryOrder"), the TriggerPrice submitted is 1688.8, and the high and low of the bar are 1688.8 and 1687.7 is this correct?

    May I confirm that this is not a renko bar type or any other bar type where the values can be changed?

    May I have you provide an example test script that is reduced to only the code to submit this one order?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      I have attached a sample script for your reveiw as well as the results that I have received after running the script through the Strategy Analyzer. Any help in identifying why the orders are not being triggered corectly would be appreciated.
      Attached Files
      MarkF60
      NinjaTrader Ecosystem Vendor - futureslivetradingrooom.com

      Comment


        #4
        Hello MarkF60,

        Thanks for your reply.

        I see that you are submitting orders to the primary data series.

        We should 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. Cases where this error is seen can 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 can be taken to analyze how the error was received.

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

        I attached the test script from the demo as well.
        Attached Files
        JimNinjaTrader Customer Service

        Comment


          #5
          Hi Jim,

          I have set the Order Fill Resolution to High in the Strategy Analyzer as instructed by the documentation (see my attached output notes above). However, I still got orders ignored plus some orders not created or triggered correctly. How do I resolve this problem whilst doing backtesting?

          The strategy works fine when State == State.Realtime
          MarkF60
          NinjaTrader Ecosystem Vendor - futureslivetradingrooom.com

          Comment


            #6
            Hello MarkF60,

            The best way to look into this would be to set up a test strategy as I have attached where we look for a certain bar to enter, or use a certain bar to submit the order in question. This helps to make the tests more manageable without needing the ~1200 lines of code to reproduce the issue.

            Could you modify the strategy I provided so it includes the prints I used and also modify it so only the orders in question are generated?

            Print this bar and next bar:

            Code:
            Print("");
            Print(String.Format("This bar: Time: {0} Open: {1} High: {2} Low: {3} Close: {4}", Bars.GetTime(CurrentBar), Bars.GetOpen(CurrentBar), Bars.GetHigh(CurrentBar), Bars.GetLow(CurrentBar), Bars.GetClose(CurrentBar)));
            Print(String.Format("Next bar: Time: {0} Open: {1} High: {2} Low: {3} Close: {4}", Bars.GetTime(CurrentBar+1), Bars.GetOpen(CurrentBar+1), Bars.GetHigh(CurrentBar+1), Bars.GetLow(CurrentBar+1), Bars.GetClose(CurrentBar+1)));
            Print("");
            Look for bar at certain time to trigger submission:
            Code:
            DateTime _Date = new DateTime(2020, 4, 23, 00, 00, 00);
            
            DateTime _CurrentDate = Time[0].Date;
            
            if (_CurrentDate == _Date && High[0] == 2801.50 && Low[0] == 2793.50)
            {
            ShortEntryPrice = Low[0] - 2*TickSize;
            ShortStopLossPrice = High[0] + 2*TickSize;
            SE = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopLimit, 1, ShortEntryPrice, ShortEntryPrice, string.Empty, "Short Entry");
            }
            I have not been able to reproduce trades or errors using the data series mentioned. I would need to know the data provider you are using and your timezone to do similar trades and give further insight. Better yet, if you can provide a link that includes an export of the data required and include that with the modified strategy and timezone, I could reproduce and give my analysis.

            Exporting data - https://ninjatrader.com/support/help...?exporting.htm

            I can note that you are using BarsAgo 1 references in your script when processing historical data. Please note that historical processing follows Calculate.OnBarClose behaviors since there is no intrabar movement. BarsAgo 1 references would be used to reference the close of a bar when processing realtime data with Calculate.OnPriceChange or Calculate.OnEachTick and using IsFirstTickOfBar to identify when we are processing a new bar. (Bar closures are signaled by the first tick of a new bar.) The example below can help illustrate.

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

            I look forward to assisting.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bosajin, Today, 09:51 AM
            2 responses
            7 views
            0 likes
            Last Post bltdavid  
            Started by Newant, Today, 08:13 AM
            2 responses
            19 views
            0 likes
            Last Post Newant
            by Newant
             
            Started by alejandro888, Yesterday, 10:14 PM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Started by devro, Yesterday, 07:00 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by mr_trade, Today, 07:13 AM
            0 responses
            18 views
            0 likes
            Last Post mr_trade  
            Working...
            X