How many bars in a year indicator

Forums ProRealTime English forum ProBuilder support How many bars in a year indicator

Viewing 2 posts - 1 through 2 (of 2 total)
  • #95091

    A piece of code that I wrote in another topic got me thinking about how many bars exactly there have been in the last year so I decided to code an indicator to find this out in any time frame. The indicator checks that we have at least a years worth of candles and then at the first candle of every day it counts the candles between today and this date one year ago.

    I tested it on a daily time frame on the DJI and I was surprised by the results. There is obviously a moment in time when the PRT data switched from 5 bars a week to 6 bars a week in 2007 and there will be differences due to leap years and holidays and maybe major events that meant that markets were closed but the graphed line was much rougher than I thought it should be with strange things like the 1988 to 1991 rise and fall with an 11 bar difference between the highest and lowest number of bars in a year in this period.

    Screenshot_1-3

    My thoughts for using the indicator were to CALL it and then use the output as a period in any indicator that needs a look back period of a year to try to improve the accuracy of back tests. For example a 310 bar look back would be a fairly representative period of one year when there are 6 bars per week but much more than a year when there were only 5 bars per week.

    It gets me thinking that when we use something like a common 200 period average for a decision in a strategy this average represents a totally different thing pre 2007 when there were 5 bars per week compared to post 2007 when there were 6 bars per week – and yet we run back test and develop strategies using it. Really we should use a 200 period average pre 2007 and a 240 period average post 2007 as 6 bars is a 20% increase on 5 bars.

    Here is the code for the indicator:

     

    Be warned – the indicator is very slow to calculate. You can speed it up by changing the two OPENDAY in line 10 to OPENWEEK or OPENMONTH but you will obvious not have the most up to date count if you do.

    4 users thanked author for this post.
    #182064

    Thanx Vonasi !
    As I see, most of major markets have around 258 traded days …. BTCUSD has 365

Viewing 2 posts - 1 through 2 (of 2 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login