Average value from a time period every day last 20 days

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #90615 quote
    PastaPesto
    Participant
    Veteran

    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

    #90619 quote
    Vonasi
    Moderator
    Master

    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
    PastaPesto and Pepsmile thanked this post
    #90622 quote
    robertogozzi
    Moderator
    Legend

    Or

    if time = 093000 then
       day1 = (high - low)
    endif
     
    ave = summation[3](day1) /3
    Vonasi, PastaPesto, Pepsmile and Oddsyuk thanked this post
    #90636 quote
    Vonasi
    Moderator
    Master

    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!

    robertogozzi thanked this post
    #90638 quote
    Nicolas
    Keymaster
    Legend

    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.

    PastaPesto thanked this post
    #90641 quote
    robertogozzi
    Moderator
    Legend

    Isn’t SUMMATION the sum of day[0] + day[1] + day[2] ?

    #90642 quote
    Nicolas
    Keymaster
    Legend

    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.

    #90643 quote
    robertogozzi
    Moderator
    Legend

    Yes, Vonasi ‘s code is the correct one!

    Thank you Nicolas for pointing that out!

    Nicolas thanked this post
    #90644 quote
    Vonasi
    Moderator
    Master

    Yes, Vonasi ‘s code is the correct one!

    Thank God for that! It means my brain is OK!

    #90673 quote
    PastaPesto
    Participant
    Veteran

    Thank you all for your help! Vonasis code worked perfectly.

    Have a nice day!

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Average value from a time period every day last 20 days


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
PastaPesto @pastapesto Participant
Summary

This topic contains 9 replies,
has 4 voices, and was last updated by PastaPesto
7 years, 7 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 02/06/2019
Status: Active
Attachments: No files
Logo Logo
Loading...