Average value from a time period every day last 20 days
Forums › ProRealTime English forum › ProBuilder support › Average value from a time period every day last 20 days
- This topic has 9 replies, 4 voices, and was last updated 5 years ago by PastaPesto.
-
-
02/06/2019 at 1:59 PM #90615
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
02/06/2019 at 2:18 PM #90619Store 20 variables and each day at 0930 move them all along one and then save the new values.
Something like this:
On a 30 minute chart1234567if time = 0930 thenday3 = day2day2 = day1day1 = (high - low)endifave = (day1 + day2 + day3) / 32 users thanked author for this post.
02/06/2019 at 2:53 PM #90622Or
12345if time = 093000 thenday1 = (high - low)endifave = summation[3](day1) /34 users thanked author for this post.
02/06/2019 at 4:29 PM #90636Thanks 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!
1 user thanked author for this post.
02/06/2019 at 4:59 PM #90638I 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.
1 user thanked author for this post.
02/06/2019 at 5:12 PM #90641Isn’t SUMMATION the sum of day[0] + day[1] + day[2] ?
02/06/2019 at 5:23 PM #9064202/06/2019 at 5:33 PM #90643Yes, Vonasi ‘s code is the correct one!
Thank you Nicolas for pointing that out!
1 user thanked author for this post.
02/06/2019 at 5:58 PM #90644Yes, Vonasi ‘s code is the correct one!
Thank God for that! It means my brain is OK!
02/07/2019 at 9:16 AM #90673Thank you all for your help! Vonasis code worked perfectly.
Have a nice day!
-
AuthorPosts
Find exclusive trading pro-tools on