Hello!
I am struggeling with an average movement between 09:00 and 09:30 (high – low). I want to sum the last 20 days and have an average. It seems easy but I really got stuck on this one. Simple example for 3 days below. I need this so there is a new average of 20 days looking back every day.
day 1: High-low (between 09:00-09:30) = 30
day 2: High-low (between 09:00-09:30) = 40
day 3: High-low (between 09:00-09:30) = 20
Average = 30
Store 20 variables and each day at 0930 move them all along one and then save the new values.
Something like this:
if time = 0930 then
day3 = day2
day2 = day1
day1 = (high - low)
endif
ave = (day1 + day2 + day3) / 3
Or
if time = 093000 then
day1 = (high - low)
endif
ave = summation[3](day1) /3
Thanks for that simpler version Roberto. Once again my brain avoided all possibilities of using SUMMATION. I don’t know why it does but it always does!
I don’t think that the Roberto version will work correctly, as the summation will be made on the last 3 periods in real time, and in the last 3 bars, the day1 value is the same.
Isn’t SUMMATION the sum of day[0] + day[1] + day[2] ?
Yes but in this case day[0] = day[1] = day[2], since you are updating the “day” variable once per day. It is a summation over 3 periods and not with 3 different data from the array.
Yes, Vonasi ‘s code is the correct one!
Thank you Nicolas for pointing that out!
Yes, Vonasi ‘s code is the correct one!
Thank God for that! It means my brain is OK!
Thank you all for your help! Vonasis code worked perfectly.
Have a nice day!