[RS]Accumulation and Distribution Divergence V0

EXPERIMENTAL: Accumulation and Distribution Divergence detection.
Remove from Favorite Scripts Add to Favorite Scripts
study(title='[RS]Accumulation and Distribution Divergence V0')

smooth = input(1)

f_top_fractal(_src)=>_src[4] < _src[2] and _src[3] < _src[2] and _src[2] > _src[1] and _src[2] > _src[0]
f_bot_fractal(_src)=>_src[4] > _src[2] and _src[3] > _src[2] and _src[2] < _src[1] and _src[2] < _src[0]
f_fractalize(_src)=>f_top_fractal(_src) ? 1 : f_bot_fractal(_src) ? -1 : 0

hist = sma(cum(close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volume), smooth)

fractal_top = f_fractalize(hist) > 0 ? hist[2] : na
fractal_bot = f_fractalize(hist) < 0 ? hist[2] : na

high_prev = valuewhen(fractal_top, hist[2], 1) 
high_price = valuewhen(fractal_top, high[2], 1)
low_prev = valuewhen(fractal_bot, hist[2], 1) 
low_price = valuewhen(fractal_bot, low[2], 1)

regular_bearish_div = fractal_top and high[2] > high_price and hist[2] < high_prev
hidden_bearish_div = fractal_top and high[2] < high_price and hist[2] > high_prev
regular_bullish_div = fractal_bot and low[2] < low_price and hist[2] > low_prev
hidden_bullish_div = fractal_bot and low[2] > low_price and hist[2] < low_prev

plot(title='HIST', series=hist, color=black)
plot(title='H F', series=fractal_top, color=regular_bearish_div or hidden_bearish_div ? black : silver, offset=-2)
plot(title='L F', series=fractal_bot, color=regular_bullish_div or hidden_bullish_div ? black : silver, offset=-2)
plot(title='H D', series=fractal_top, style=circles, color=regular_bearish_div or hidden_bearish_div ? maroon : gray, linewidth=3, offset=-2)
plot(title='L D', series=fractal_bot, style=circles, color=regular_bullish_div or hidden_bullish_div ? green : gray, linewidth=3, offset=-2)

plotshape(title='+RBD', series=regular_bearish_div ? hist[2] : na, text='R', style=shape.labeldown, location=location.absolute, color=maroon, textcolor=white, offset=-2)
plotshape(title='+HBD', series=hidden_bearish_div ? hist[2] : na, text='H', style=shape.labeldown, location=location.absolute, color=maroon, textcolor=white, offset=-2)
plotshape(title='-RBD', series=regular_bullish_div ? hist[2] : na, text='R', style=shape.labelup, location=location.absolute, color=green, textcolor=white, offset=-2)
plotshape(title='-HBD', series=hidden_bullish_div ? hist[2] : na, text='H', style=shape.labelup, location=location.absolute, color=green, textcolor=white, offset=-2)
Great job again! Thank you for developing this and for including the smoothing factor! I want to experiment with comparing to your other divergence work and volume if you are able to do it.
Hello Ricardo,

The indicator is not loading. I tried different timings but still it just shows "loading" and then its blank. Can you please help me with it?
RicardoSantos PRO rinku.singh.111
check if you have volume information.
rinku.singh.111 RicardoSantos
Can you please guide me how do I check that?
RicardoSantos PRO rinku.singh.111
top buttons bar --> indicators --> builtins --> volume.
if it shows volume bars its working if it doesnt show anything its not.
rinku.singh.111 RicardoSantos
No it's not showing up. How do I get it working?
rinku.singh.111 RicardoSantos
It's intermittent. It is sometimes working and sometimes not. This is a very good indicator and I surely do not want to miss it
RicardoSantos PRO rinku.singh.111
on forex pairs i sugest use idc exchange for data as theyr volume info is more complete than fxcm
rinku.singh.111 RicardoSantos
I trade in Crude Oil. Any other way to get this working? Do you have same indicator in MT4?
RicardoSantos PRO rinku.singh.111
CL1! but you will need to subscribe for intraday data.
This is a fantastic piece of work Ricardo. Do you have any intention of porting it to MT4?
i do not
Hola Ricardo, siempre me ha gustado trabajar las divergencias y este indicador me parece muy acertado. Una pregunta: ¿Sería posible añadir una alerta a la señal de divergencia?.


Ideas Scripts Chart
United States
United Kingdom
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
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Account and Billing Sign Out