How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Feature Request FAQ Help & Wiki Twitter

# [RS]Price Advance & Decline Range Analysis

365 0
i use this mainly to extract average Advance and Decline values to use on linear regression lines.
```study(title="[RS]Price Advance & Decline Range Analysis V0", shorttitle="PA&DRA.V0", precision=5)
seriesA = input("open")
seriesB = input("close")
AverageType = input("cap")
length = input(24)

sa = seriesA == "open" ? open :
seriesA == "close" ? close :
seriesA == "high" ? high :
seriesA == "low" ? low :
seriesA == "hl2" ? hl2 :
seriesA == "hlc3" ? hlc3 :
seriesA == "ohlc4" ? ohlc4 : na

sb = seriesB == "open" ? open :
seriesB == "close" ? close :
seriesB == "high" ? high :
seriesB == "low" ? low :
seriesB == "hl2" ? hl2 :
seriesB == "hlc3" ? hlc3 :
seriesB == "ohlc4" ? ohlc4 : na

//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])
pdfappex = nz(pdfappex[1]) <= posdifrange ? posdifrange : nz(pdfappex[1])
ndfappex = nz(ndfappex[1]) >= negdifrange ? negdifrange : nz(ndfappex[1])

avgposrange = AverageType == "cap" ? cum(posdifrange)/(1+n) :
AverageType == "sma" ? sma(posdifrange, length) :
AverageType == "ema" ? ema(posdifrange, length) :
AverageType == "dema" ? ema(ema(posdifrange, length),length) : na
avgnegrange = AverageType == "cap" ? cum(negdifrange)/(1+n) :
AverageType == "sma" ? sma(negdifrange, length) :
AverageType == "ema" ? ema(negdifrange, length) :
AverageType == "dema" ? ema(ema(negdifrange, length),length) : na

avgmaxposrange = pdfappex * 0.7
avgmaxnegrange = ndfappex * 0.7

//plot(difrange)
plot(posdifrange, color=green, style=columns)
plot(negdifrange, color=red, style=columns)

//plot(dfappex, color=gray)
ta0 = plot(pdfappex, color=maroon, style=circles, linewidth=1)
ba0 = plot(ndfappex, color=green, style=circles, linewidth=1)

plot(avgposrange, color=gray, linewidth=2)
plot(avgnegrange, color=gray, linewidth=2)

ta1 = plot(avgmaxposrange, color=red, linewidth=1)
ba1 = plot(avgmaxnegrange, color=lime, linewidth=1)

fill(ta0, ta1, color=red, transp=75)
fill(ba0, ba1, color=lime, transp=75)

hline(0, color=black)```
United States
United Kingdom
India
España
France
Italia
Polska
Brasil
Россия
Türkiye
Indonesia

한국
Home Stock Screener Forex Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter