Arindam Ghosh
 · Algo Trader

Hi, Can anyone who uses Pine Script, please explain me what this below code is doing step by step? I want to code it in Python. Depth = input(12, title="Depth") Deviation = input(5, title="Deviation") lastlow = 0.0, lasthigh = 0.0 lastlow := nz(lastlow[1]) lasthigh := nz(lasthigh[1]) data(x) => d = security(syminfo.tickerid, timeframe.period, x) d getLow(x, y, z, a) => lastlow = y v = data(x) m = v==lastlow or data(z) - v > a*syminfo.mintick if v!=lastlow lastlow := v if m v := 0.0 [v,lastlow] getHigh(x, y, z, a) => lasthigh = y v = data(x) m = v==lasthigh or v - data(z) > a*syminfo.mintick if v!=lasthigh lasthigh := v if m v := 0.0 [v,lasthigh] [v,e] = getLow(lowest(Depth), lastlow, low, Deviation) lastlow := e zBB = v != 0.0 [v1,e1] = getHigh(highest(Depth), lasthigh, high, Deviation) lasthigh := e1 zSS = v1 != 0.0 zigzagDirection = -1 zigzagHigh = 0 zigzagLow = 0 zigzagDirection := zBB ? 0 : zSS ? 1 : nz(zigzagDirection[1], -1) virtualLow = zigzagLow[1] + 1 if not zBB or (zBB and zigzagDirection == zigzagDirection[1] and low > low[virtualLow]) zigzagLow := nz(zigzagLow[1]) + 1 virtualHigh = zigzagHigh[1] + 1 if not zSS or (zSS and zigzagDirection == zigzagDirection[1] and high < high[virtualHigh]) zigzagHigh := nz(zigzagHigh[1]) + 1 line zigzag = line.new(bar_index-zigzagLow, low[zigzagLow], bar_index-zigzagHigh, high[zigzagHigh], color=color.red, style=line.style_solid, width=2) if (zigzagDirection == zigzagDirection[1]) line.delete(zigzag[1])

3 replies