Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.

    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 sidlercom80, 10-28-2023, 08:49 AM
                168 responses
                2,262 views
                0 likes
                Last Post sidlercom80  
                Started by Barry Milan, Yesterday, 10:35 PM
                3 responses
                10 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by WeyldFalcon, 12-10-2020, 06:48 PM
                14 responses
                1,429 views
                0 likes
                Last Post Handclap0241  
                Started by DJ888, 04-16-2024, 06:09 PM
                2 responses
                9 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                41 views
                0 likes
                Last Post jeronymite  
                Working...
                X