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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//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