All time average in an indicator.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #75196 quote
    VonasiVonasi
    Moderator
    Master

    I’m coding an indicator and I wanted to calculate an all time average of a value in it but I couldn’t get a value out of it. Here a simplified version of the first attempt:

    a = (my calculation)
    
    c = c + 1
    d = d + a
    
    ave = d / c

    I then changed it to this and it works:

    a = (my calculation)
    
    if a > 0 then
    c = c + 1
    d = d + a
    endif
    
    ave = d / c

    I’m trying to understand why one works and the other doesn’t – can anyone explain?

    #75197 quote
    NicolasNicolas
    Keymaster
    Legend

    First time you made the calculation, d is equal to 0 and thus made a division by zero error.

    #75200 quote
    VonasiVonasi
    Moderator
    Master

    Is this because the values are calculated live/on the fly? My brain is thinking the value is set at bar close but that might be because it has spent too much time doing end of bar strategies!

    So it is the same if you want to use the AVERAGE instruction – you must do this:

    a = (my calculation)
     
    if a > 0 then
    d = average[21](a)
    endif

    or even this slightly messy version:

    a = (my calculation)
     
    Once a = 0.000000000000001
    
    d = average[21](a)
    

    or even this:

    a = max((my calculation), 0.000000000000001)
    
    d = average[21](a)
Viewing 3 posts - 1 through 3 (of 3 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

All time average in an indicator.


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Vonasi @vonasi Moderator
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by VonasiVonasi
8 years, 3 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 07/04/2018
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...