I have the following pinescript code and I am trying to understand it correctly.
//@version=5
modevalue = input.int(title ="[ATR] Atr Period", defval = 14, minval = 1)
//calc atr val
conv_atr(valu)=>
a = 0
num = syminfo.mintick
s = valu
if na(s)
s := syminfo.mintick
if num < 1
for i = 1 to 20
num := num * 10
if num > 1
break
a := a +1
for x = 1 to a
s := s * 10
s := math.round(s)
for x = 1 to a
s := s / 10
s := s < syminfo.mintick ? syminfo.mintick : s
s
//ATR box size calculation
atrboxsize = conv_atr(ta.atr(modevalue))
No question on the function conv_atr
. I am wondering what the line atrboxsize = conv_atr(ta.atr(modevalue))
does.
As far as I learned, pinescript engine loops through each bar one by one. Also, the statement involving atrboxsize
is an initialization statement which mean it is calculated at the very beginning of the run. However, it involves ta.atr(14)
that requires the last 14 bars prior to the current bar which is the very first bar.
So, what are the details of calculating atrboxsize
?