# [RS]Price Linear Sequence Counter

1536 lượt xem
Simple green/red sequence counter, also gives current highest achieved sequence(black lines).
```study(title="[RS]Price Linear Sequence Counter", shorttitle="[RS]PLSC.V0")
length = input(24)

sa = open

sb = close

//difrange = abs(sa-sb)
posdifrange = sb-sa >= 0 ? sb-sa : 0
negdifrange = sb-sa <= 0 ? sb-sa : 0

//dfappex = nz(dfappex[1]) <= difrange ? difrange : nz(dfappex[1])

poslinearsequence = posdifrange > 0 ? nz(poslinearsequence[1]) + 1 : 0
neglinearsequence = negdifrange < 0 ? nz(neglinearsequence[1]) - 1 : 0

plinappex = nz(plinappex[1]) <= poslinearsequence ? poslinearsequence : nz(plinappex[1])
nlinappex = nz(nlinappex[1]) >= neglinearsequence ? neglinearsequence : nz(nlinappex[1])

plot(poslinearsequence, color=green, style=columns)
plot(neglinearsequence, color=red, style=columns)
//plot(difrange)
//colorf(v, c) => v != 0 ? c : na
//plot(posdifrange, color=colorf(posdifrange, green), style=circles, linewidth=2)
//plot(negdifrange, color=colorf(negdifrange, red), style=circles, linewidth=2)

plot(plinappex, color=black)
plot(nlinappex, color=black)
hline(0, color=black)```