Trying to convert pinescript to AFL . Pine code is given below.
nATRPeriod = input(20, 'Period')
nATRMultip = input.float(5, 'Multiplier', minval=1, maxval=1000, step=1)
/////////////////////////////////////////////////////////////////////////////////ATR
xATR = ta.atr(nATRPeriod)
nLoss = nATRMultip * xATR
xATRTrailingStop = float(na)
iff_1 = close > nz(xATRTrailingStop[1], 0) ? close - nLoss : close + nLoss
iff_2 = close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0) ? math.min(nz(xATRTrailingStop[1]), close + nLoss) : iff_1
xATRTrailingStop := close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), close - nLoss) : iff_2
pos = int(na)
iff_3 = close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0) ? -1 : nz(pos[1], 0)
pos := close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0) ? 1 : iff_3
patr = plot(xATRTrailingStop, color=color.new(color.aqua, 0), linewidth=1, title='AT', transp=0)
src = input(hlc3)
//t = time("D")
start = na(pos[1]) or pos > pos[1] or na(pos[1]) or pos < pos[1]
sumSrc = src * volume
sumVol = volume
sumSrc := start ? sumSrc : sumSrc + sumSrc[1]
sumVol := start ? sumVol : sumVol + sumVol[1]
out = sumSrc / sumVol
avg1 = math.avg(out, xATRTrailingStop)
//plot(avg1)
plot(out, color=color.new(color.aqua, 0), title='CV')
type or paste code here