hi… had a look at your code to see if I could see any problems other than your love of ‘brackets’!
Couldn’t see anything other than the ‘brackets’, and the differences of line 3 and it seemed to work for me.
In trying to understand and verify it was correct I created an alternate version, while debugging, with line plots to see, when the range’s crossed over the average’s, the bar’s were in the right position. Also I wonder about using the stock average function, so I incorporated that in as well to compare with manual calculated version. This gave the added benefit of changing the average type to EMA and other’s. Then there were a few only things and then four hour’s later…
By adding 4 identical indicators and using different setting for each, see pic panel labels, you can see whats happening and make a comparison. When lines cross and different average’s. One thing I did find interesting, is the 5 daily values for the average calculation required a value of ‘6’ in the average function to make them the same, not sure why yet.
The variables in settings, ‘page’ switches between line/bar, ‘choice’ between manual/stock average calculation, ‘aveType’ set the type of average, ‘avetext’ turns on/off text for number type of ‘aveType’
[attachment file=”197335″]
Pic 1 shows price, and 2 sets of similar panels. The top 2 show the range/average range lines and the bars of the manual calculated SMA version while the bottom 2, are the same but using the Average function. Pic 2 is similar but the bottom 2 are set to ema.
[attachment file=”197336″]
The code file below is what I ended up with. When importing it should set the dynamic variable’s if not there listed at the top of the code. I’ve hard coded the colors and styles so it should look good out of the box, but there an alternate RETURN statement you can switch between if you want to set them in the indicator settings.