• 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

Determining bars required

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

    Determining bars required

    For backtesting purposes if it matters. How do you determine what your bars required number should be? It seems 20 is the standard default but what is the significance or purpose for that?

    If I am using a 50MA does this mean my bars required needs to be 50?

    #2
    Hello zachj,

    Thank you for your post.

    That is correct, you are going to want more bars on the chart than your period by at least one. The period would be the number of bars used to calculate so it makes sense we need that many bars before the values can be calculated.

    For information on making sure you have enough bars on your chart before accessing them please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3170

    Please let me know if I may be of further assistance.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      So with the 50MA and using a 5min chart it would take about 4hrs for the 50MA to form so the first trade could not be until about 130pm. But say I had my bars required set to 20 that would allow the first trade to be around 1115am as I can see from looking at the trades in the backtest. So what does it do just resort to a 20 bar MA?

      Comment


        #4
        Originally posted by zachj View Post
        So with the 50MA and using a 5min chart it would take about 4hrs for the 50MA to form so the first trade could not be until about 130pm. But say I had my bars required set to 20 that would allow the first trade to be around 1115am as I can see from looking at the trades in the backtest. So what does it do just resort to a 20 bar MA?
        If you want to open trades based on a 50-period MA, then in any case you need appropriate data for calculating the 50-period MA. I would not consider it as a serious option to use a 20-period MA instead, just because there is no data on the chart.

        For a 50-period SMA you would need at least 50 bars. For a 50-period EMA you may need as many as 100 bars to approach the correct value of the moving average. This is because the EMA is an IIR filter (infinitive impulse response filter) that calculates the current value by using the EMA values of the preceding bars.

        For your 50-period moving average, you can use data of the prior day. Markets are now mostly running around the clock, why would you want to start calculations with the daybreak?

        If you wish to use a session indicator that only takes into account trades of the current session, I would recommend a VWAP over a traditional moving average.

        Comment


          #5
          Again just stocks. How would I have it use data from the prior day for the 50MA, by setting it to 24/7? Then I would get AH and PM data which I do not want.

          Comment


            #6
            If you use the US Equities RTH session template, you will only get data for the regular cash session and would exclude the PM hours.
            MatthewNinjaTrader Product Management

            Comment


              #7
              Yes I realize that but Harry mentioned I could use data of the prior day which I assume he is talking about the 24/7 setting but that will include AH/PM which I do not want. This went off track and one of my original questions wasn't really answered, I was just curious if I have it set for 20 for bars required and I have a 50 MA in my script will it just resort to a 20 MA, then 21 MA and so on until it reaches a 50 MA? I will just set it to 50 or 51 but just was curious how it operates when enough data is not available. And I do realize that it will just not take the trade if its set to RTH and that it will only do this for 24/7 setting.

              Comment


                #8
                Originally posted by zachj View Post
                Yes I realize that but Harry mentioned I could use data of the prior day which I assume he is talking about the 24/7 setting but that will include AH/PM which I do not want. This went off track and one of my original questions wasn't really answered, I was just curious if I have it set for 20 for bars required and I have a 50 MA in my script will it just resort to a 20 MA, then 21 MA and so on until it reaches a 50 MA? I will just set it to 50 or 51 but just was curious how it operates when enough data is not available. And I do realize that it will just not take the trade if its set to RTH and that it will only do this for 24/7 setting.
                For all indicators there is a training period, during which the indicator dispalys false values. The best option is not to use indicators when the training period is not yet complete.

                Whether a 50 MA will resort to a 20 MA or not depends on

                -> the type of the moving average
                -> and the formula that is used

                There are different ways for each indicator to code an approximation for the training period, and you really need to check the script. The NinjaTrader SMA(50) will resort to SMA(19), if there are only 19 bars on your chart and to a SMA(37), if there are 37 bars. With an EMA this is not possible, as the training period is longer than the indicator period.

                The best option is to code a new indicator that works in the way you have described.
                For example I have coded a SMA that detects the first bar of the regular session and then calculates a simple moving average that gradually builds up until the number of bars equivalent to the selected lookback period is reached. I use this inidcator on the NYSE Tick, as I am not interested to include any tick readings from the prior evening to determine the trend of the current day.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by pulpiwapi, 03-04-2019, 11:18 PM
                11 responses
                143 views
                0 likes
                Last Post music_p13  
                Started by indy73, Yesterday, 10:52 PM
                3 responses
                17 views
                0 likes
                Last Post sledge
                by sledge
                 
                Started by priceisking, Today, 12:51 PM
                1 response
                18 views
                0 likes
                Last Post NinjaTrader_PaulH  
                Started by chartish, Today, 10:33 AM
                3 responses
                26 views
                0 likes
                Last Post chartish  
                Started by casabella, Today, 11:51 AM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_PaulH  
                Working...
                X