• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entry discrepancies with MTF strategies in backtest

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

    Entry discrepancies with MTF strategies in backtest

    Hi,

    I am using a multitimeframe strategy. Entry is on 3 min. When backtesting this strategy, the 1 min chart shows an entry discrepancy of 2 bars (see image), meaning it enters the trade 2 min too late.

    This is critical when one feature of this strategy is a Breakeven SL, which will be set when a predefined Low[0] is met. However, when entering 2 min too late means to miss out this Low[0] this trade is executed incorrectly and I get a note in the log that

    "Default Strategy 'Bearengulfstrategyexecutionmethod/114873690': A BuyToCover stop order placed at '21.06.2016 09:45:00' has been ignored since the stop price is less than or equal to the close price of the current bar. This is an invalid order and subsequent orders may also be ignored. Please fix your strategy."

    Is there an explanation for this behaviour?

    Cheers,

    slimwin
    Attached Files

    #2
    Hello slimwin,

    Is the strategy running with Calculate as OnBarClose?

    Are you submitting orders after the bar closed?

    Below is a publicly available link to the help guide on the Calculate property.
    http://ninjatrader.com/support/helpG.../calculate.htm

    This means that any orders that are triggered from that bar are submitted after the bar closes as the new bar opens. As the order is placed as the new bar opens and the timestamp of the order is within the time of the next bar, the order will show on the next bar.

    If the strategy were running with Calculate as OnPriceChange or OnEachTick, or if the script has intra-bar granularity and submitted orders on a smaller timeframe, this would cause the timestamp of the order to be within the bar it is triggered on as the order may be submitted intra-bar. This order would show on the same bar as the bar that triggered the order submission.

    This is outlined in the help guide Discrepancies: Real-Time vs Backtest. Below is a publicly available link to the help guide.
    http://ninjatrader.com/support/helpG...ime_vs_bac.htm

    Also, below is a link to a forum thread about intra-bar granularity.
    http://ninjatrader.com/support/forum...297#post491297
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello ChelseaB,

      thanks for the fast response!

      Although the signals are generated based on closed bars (which I think is achieved with IsFirstTickOfBar), the strategy calculates on OnEachTick. I need this for the indicator calculation based on 1 min data. So, while the 1min data is only used for the TP purpose (which works well), everything else as initial SL and BE SL are set based on 3min data.

      I hope this quick logic overview helps to understand this:

      Code:
      if (BarsInProgress == 0)
      {
          if (Position.MarketPosition == MarketPosition.Short && BE condition)
              Set BE SL;
      
          if (IsFirstTickOfBar && CurrentBar > BarsRequiredToTrade)
          {
              if(entry condition)
                entryshort;
          } 
          else 
               return;      
      } 
      else if(BarsInProgress == 1)
      {
          if(Position.MarketPosition == MarketPosition.Short && TP condition)
             exit short;
      }
      Entryorder is assigned in OnExecutionUpdate(), Initial SL and resetting of it in OnOrderUpdate().

      In the end, I have found out that this problem always occurs when on the 3 min chart the bar after the signal bar (so on the chart it seems as if it is the entry bar, but technically it is obviously not the case) meets the BE condition, but reverses and closes above the signals bars close. Furthermore, the strategy performance window shows long trades, although this is an only short strategy. I suppose this has something to do with the problem here discussed.

      Comment


        #4
        Hello slimwin,

        From the logic you have posted, it looks like there is a sell market order being placed on the next bar update for BarsInProgress 1.

        What is BarsInProgress 1? Is this an added tick series?

        If you have intra-bar granularity, there would not be a need to use Calculate.OnEachTick as each tick would already be processed as its own series..

        I would expect after the entry is placed, and the position is updated, for the exit order to be placed on the next close of the BarsInProgress 1 bar..


        The error is letting you know you are using an invalid price for stop order.
        What is the current market price when the stop order is placed?
        Are you ensuring that the price of the order is above the current ask before placing the order?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello ChelseaB,

          BarsInProgress 0 is an EnterShort order (triggered by price conditions from 3 min bars) and the BarsInProgress 1 is an ExitShort order (based on indicator conditions retrieved from an added data series in 1 min form).

          I understand the settings as following:
          In BarsInProgress 0, based on the code and although Calculate.OnEachTick is set, the entry conditions are only calculated with each new bar created (by IsFirstTickOfBar), thus intrabar ignored. However, BE conditions are calculated on each tick, if a short position is open. Also BarsInProgress 1 is calculated on each tick and if a short market position is open and the indicator conditions (based on the 1min added data series) are met, the ExitShort Order is executed.

          I have chosen this settings, because I have read that it is impossible to use different calculation modes for different timeframes in one strategy..
          Attached Files

          Comment


            #6
            Hello slimwin,

            BarsInProgress represents which bars series is processing when OnBarUpdate is triggered.

            I am asking your what bar series is processing when BarsInProgress is equal to 1.

            That said, if an order is being placed on the first tick of a new bar, what is the specific issue you are having?

            Is the order being placed on the wrong bar?

            Do you have any prints to print when the order in question is being submitted?

            Is the entry on the right bar?

            Is the exit on the right bar?

            When are these orders being submitted?

            When are the orders being filled?

            If you are using multiple data series, which BarsInProgress is the order being submitted to?

            What is the bars period of the added series?

            Please include the output from your prints.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello ChelseaB,

              sorry for the confusion.

              Thats the print from the output:

              21.06.2016 09:42:00 Strategy 'Bearengulfstrategyexecutionmethod/114873698': Entered internal SubmitOrderManaged() method at 21.06.2016 09:42:00: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=4 LimitPrice=0 StopPrice=0 SignalName='BearEng1' FromEntrySignal=''
              entryOrder != null
              entryOrder == null reset
              Hypothetical Entry Price is Close: 9961
              BE price trigger: 9951,5
              21.06.2016 09:42:00 Strategy 'Bearengulfstrategyexecutionmethod/114873698': Entered internal SubmitOrderManaged() method at 21.06.2016 09:42:00: BarsInProgress=0 Action=BuyToCover OrderType=StopMarket Quantity=4 LimitPrice=0 StopPrice=9970,5 SignalName='SL' FromEntrySignal='BearEng1'
              stopOrder != null SL is set
              entryOrder == null reset because SL
              21.06.2016 09:45:00 Strategy 'Bearengulfstrategyexecutionmethod/114873698': Entered internal SubmitOrderManaged() method at 21.06.2016 09:45:00: BarsInProgress=0 Action=BuyToCover OrderType=StopMarket Quantity=4 LimitPrice=0 StopPrice=9961,0 SignalName='BE' FromEntrySignal='BearEng1'
              Strategy 'Bearengulfstrategyexecutionmethod/114873698': A BuyToCover stop order placed at '21.06.2016 09:45:00' has been ignored since the stop price is less than or equal to the close price of the current bar. This is an invalid order and subsequent orders may also be ignored. Please fix your strategy.
              21.06.2016 09:45:00 Strategy 'Bearengulfstrategyexecutionmethod/114873698': Ignored SubmitOrderManaged() method at 21.06.2016 09:45:00: BarsInProgress=0 Action=BuyToCover OrderType=StopMarket Quantity=4 LimitPrice=0 StopPrice=9961,0 SignalName='BE' FromEntrySignal='BearEng1' Reason='Invalid order price, please see log tab'
              stopOrder != null BE is set. Current Low: 9950

              My issue is that the BE SL is not set, but ignored, although all conditions are met. So as you can see above, the price trigger for the Breakeven(BE) SL is 9951,5. The current market low reaches 9950, but the BE SL is not set, because the stop price were to be lower than the price of the bar, which is wrong as we can see in the 1 min chart. There we have two bars which are lower than the market price, but these are missed out.

              Hope I could make things clear?

              Comment


                #8
                Hello slimwin,

                While there is not enough information in your prints, it does appear that a buy stop market order is being placed at or below the ask price and this is causing the order to be rejected.

                At 9:42:00 the close price is possibly 9961?
                Originally posted by slimwin View Post
                Hypothetical Entry Price is Close: 9961
                I am making the assumping you are printing Closes[0][0].. May we see the print you coded to print this print?

                However we do not know what the ask is.

                Then a stop is placed at 9970,5
                Originally posted by slimwin View Post
                21.06.2016 09:42:00 Strategy 'Bearengulfstrategyexecutionmethod/114873698': Entered internal SubmitOrderManaged() method at 21.06.2016 09:42:00: BarsInProgress=0 Action=BuyToCover OrderType=StopMarket Quantity=4 LimitPrice=0 StopPrice=9970,5 SignalName='SL' FromEntrySignal='BearEng1'
                9970,5 sounds like it would be reasonably high enough above the current close price that it would also be above the ask price as well.

                Then at 9:45:00 there is an other order submission with the price at 9961,0.
                Originally posted by slimwin View Post
                21.06.2016 09:45:00 Strategy 'Bearengulfstrategyexecutionmethod/114873698': Entered internal SubmitOrderManaged() method at 21.06.2016 09:45:00: BarsInProgress=0 Action=BuyToCover OrderType=StopMarket Quantity=4 LimitPrice=0 StopPrice=9961,0 SignalName='BE' FromEntrySignal='BearEng1'
                However there is no print to show what the ask price is.
                If this were placed at 9:42 it would have been rejected for being at or below the ask.

                At 9:45 I'm not sure what the ask is.. but it could be very likely that the order is being placed below the ask.

                I advise that you check the current ask price, and make sure your buy stop market order is above it by at least one tick.

                If this is not resolving the error, please include the print as well as the output that shows the ask price before the stop order is submitted.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by pjsmith, Today, 02:20 AM
                0 responses
                1 view
                0 likes
                Last Post pjsmith
                by pjsmith
                 
                Started by faisamtrader, Yesterday, 10:03 PM
                0 responses
                3 views
                0 likes
                Last Post faisamtrader  
                Started by johnnybegoode, Yesterday, 08:11 PM
                0 responses
                2 views
                0 likes
                Last Post johnnybegoode  
                Started by Bionian, Yesterday, 02:47 PM
                2 responses
                21 views
                0 likes
                Last Post Bionian
                by Bionian
                 
                Started by RickB60, Yesterday, 01:55 PM
                1 response
                11 views
                0 likes
                Last Post NinjaTrader_PaulH  
                Working...
                X