• 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

Intrabar Indicator Values in Backtest

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

    Intrabar Indicator Values in Backtest

    Does NinjaTrader calculate the intrabar indicator values for backtests when testing a strategy that uses CalculateOnBarClose = false;?

    If not, is there a work around to this as this would seem not to give very accurate results for testing purposes?

    If so, is it possible to view these values or would I just need to add print statements to the code and research the values that way?

    #2
    Hi there, NinjaTrader does not run through every tick of every bar during a backtest if COBC = false. To add this functionality, please see this reference sample for adding intrabar granularity to backtests - http://www.ninjatrader-support.com/v...ead.php?t=6652.
    AustinNinjaTrader Customer Service

    Comment


      #3
      So, if for example I watch 60 minute bar charts but want my strategy to trigger intrabar (before the current 60 minute bar closes) based on real-time indicator values, the back test would show the intrabar 60 minute indicator values (i.e what they would have been real-time) or the indicator value of the secondary bar (1 tick)?

      Comment


        #4
        The backtest would show the 60 minute bars. The secondary series (1 tick series) would be hidden from view, but the backtester would move through all of those 1 tick bars before the next 60 minute bar was encountered.
        AustinNinjaTrader Customer Service

        Comment


          #5
          And this brings me back to my original question, would the orders be triggered from the 60 minute bar intrabar values like it would in real-time or would the orders be triggered from the 60 minute bar closed values.

          In looking at the documentation you linked to it seems that the orders would be triggered from the 60 minute bar data and please on the tick data for more accuracy. I read it as the backtest would not look at the 60 minute intrabar indicator values, though.

          Please clarify.

          Comment


            #6
            teak2, you can have the entries based on either timeframe, depending on how you code the strategy. If your main series was the 60 minute bar and your secondary series was the 1 tick bar, you could do something like this to read entries from the 60 minute bars but submit the orders to the smaller timeframe for execution:
            Code:
            OnBarUpdate()
            {
              if (BarsInProgress == 0) // check the 60 min bars only in this code block
              {
                 if (Close[0] > Close[1]) // very simple entry conditions
                 {
                    EnterLong(1, 1, "long 60 min entry"); // send the order to the secondary time series (with bar index = 1) for quantity 1
                 }
               }
            }
            The above would send an order to the first tick after the last 60 minute bar update.

            There are a few key ideas here, like BarsInProgress - http://www.ninjatrader.com/support/h...inprogress.htm
            The EnterLong() method used - http://www.ninjatrader.com/support/h.../enterlong.htm
            Also, please take a look at the built-in multi timeframe sample for additional sources on this - Tools -> Edit NinjaScript -> Strategy -> SampleMultiTimeFrame.
            AustinNinjaTrader Customer Service

            Comment


              #7
              In your example would the strategy analyzer look at close values from the 60 minute bar indicator?

              If you used the BarsInProgress code and look at the secondary values this would not be the same as a real-time 60 minute indicator value, correct?

              That is my goal, how do I get the most accurate backtest results testing a strategy that using indicators based on intrabar values. Can this be done accurately with NT?

              Comment


                #8
                Yes, the sample would only look at the closes of the 60 minute bar because it is in the BIP = 0 check.

                Can you please clarify your second question?

                The most accurate way to backtest is to run your strategy on the Market Replay connection, where everything is simulated to quarter second resolution.
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  An example in real-time:

                  Code:
                  CalculateOnBarClose = false;
                  
                  protected override void OnBarUpdate()
                  {
                      if(MACD(12,26,9).Diff[0] > MACD(12,26,9).Diff[1])
                      {
                      EnterLong(100000);
                      }
                   }
                    
                  Now lets say I am using a 60 minute bar chart with this example (of course there would be more code) and 20 minutes into the bar the current bar MACD Diff was greater than the previous bars MACD Diff I would want to go long at that exact time and not wait until the 60 minute bar closes. This can be done in real-time but how can I accurately backtest this and get accurate performance statistics?

                  Comment


                    #10
                    teak2, I will have someone get back to you tomorrow.
                    AustinNinjaTrader Customer Service

                    Comment


                      #11
                      teak2, to backtest this you would need to recode your conditions / indicator calcs to use lower granularity data for example a 1 min series, an approximation can be using simply longer indicator length settings that mimic then the higher timeframe study.
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Thank you for your reply. I am very surprised that NT does not have an accurate backtesting engine as that is a must for any serious automated strategy developer.

                        Comment


                          #13
                          teak2, I'm not following you - if you're testing on one series like your 60 min you will have exactly this series OHLCV data available in backtesting, if you look to recreate intrabar indicator values you would need to work with finer granularity data to replicate those as otherwise the needed resolution is not available. You could also work in Market Replay with the CalculateOnBarClose set to false though to test this setup.
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            So basically the way to get this accurate (up to the minute at least) intrabar indicator value is to change the strategy code for backtesting (probably separate strat for testing) on one minute data instead of 60 min? So code is based on 60 min. indicator values but backtested on 1 min. data.

                            So how would i convert the standard MACD values to reflect the value of the 60 minute indicator on a 1 minute interval?

                            Also, I assume I will not be able to get any more accurate than the 1 min because I would not be able to convert 60 min. MACD values to tick data, correct?

                            Comment


                              #15
                              teak2, it would depend on your custom coding here, if you simulate the 60 mins bar calcs from the tick interval you could use this as well. But you basically have to get pretty advanced in your coding here, it might be easier to use the Market Replay feature / CalculateOnBarClose = false as setting for running your scripts.
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by XimoTrader, Today, 12:57 PM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_PatrickG  
                              Started by FxInception, Today, 12:27 PM
                              2 responses
                              8 views
                              0 likes
                              Last Post FxInception  
                              Started by siroya, Today, 10:34 AM
                              1 response
                              20 views
                              0 likes
                              Last Post NinjaTrader_ShawnB  
                              Started by Leeroy_Jenkins, Today, 11:22 AM
                              2 responses
                              12 views
                              0 likes
                              Last Post Leeroy_Jenkins  
                              Started by RedDuke, Today, 10:27 AM
                              2 responses
                              15 views
                              0 likes
                              Last Post RedDuke
                              by RedDuke
                               
                              Working...
                              X