This is bizarre. I basically want to get the average of the last x amount of bars.
Even when I set the loop to 1 it doesnt calculate properly.
Pseudo code should be something like this:
- Go back 10 bars and add up all the bar ranges
- Divide the total amount by the lookbackperiod when the loop has completed
The calculations are completely incorrect. Im stuck as I cant see anything wrong with the code. Line 15 seems to be the problem but why?
Note: I am running this on the m6e futures which is why I multiply by 10000
//Grantx
defparam drawonlastbaronly=true
//--- settings
Loockbackperiod = 10
//--- end of settings
RngeSum = 0
largestBar = 0
FOR i = 0 TO Loockbackperiod DO
if (Range[i]>largestBar) THEN
largestBar = Range[i]
ENDIF
RngeSum = RngeSum + Range[i]
NEXT
//RngeSum = Round((RngeSum / Loockbackperiod)*10000)
RngeSum = Round(RngeSum*10000)
largestBar = largestBar*10000
drawtext(" ABR(#Loockbackperiod#) = #RngeSum# ¬ LB = #largestBar#",barindex,High,Dialog,Standard,10) coloured(0,0,255)
RETURN
Does below (for Lines 9 and 10) make any difference?
ONCE RngeSum = 0
ONCE largestBar = 0
You are summing up 11 bars (0 – 10), not 10.
will
LookBackPeriod = 10
AverageRange = summation[LookBackPeriod](range) / LookBackPeriod
do?
Yep. This works. Thank you!
Also, thanks @GraHal for replying.
Much appreciated.