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:
1
2
3
4
5
6
a=(mycalculation)
c=c+1
d=d+a
ave=d/c
I then changed it to this and it works:
1
2
3
4
5
6
7
8
a=(mycalculation)
ifa>0then
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?
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:
To help us continually offer you the best experience on ProRealCode, we use cookies. By clicking on "Continue" you are agreeing to our use of them. You can also check our "privacy policy" page for more information.Continue