KXRCapital

CM_Williams_Acceleration-Deceleration-Osc_System

osc
60
osc
Chris Moody

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
//Created by user ChrisMoody by request for deejmoney
//Option to plot Traditional Williams Acceleration Deceleration Indicator - Currently a 4 color histogram.
//Option to plot Threshold bands based on a lookback period and percentile of the Highs and Lowes of Indicator.
 
study(title="CM_Williams_Acceleration-Deceleration-Osc_System", shorttitle="CM_Williams Accel_Decel_Osc_System", overlay=false)
src = (hl2)
savg = input(5, title="Short MA")
lavg = input(34, title="Long MA")
col_Hist = input(true, title=" Use Threshold Histogram = Check, or 4 Color Histogram")
pt = input(.90, title="Percent Threshold of Highs and Lows - Use Decimal for %")
lb = input(100, title="Lookback Period For Threshold Percent")
stl = input(true, title="Show Upper and Lower Threshold Lines?")
stml = input(true, title="Show Mid-Lines Based on LookBack Period of Highs and Lows")
sl = input(true, title="Show Acc/Dec Line?")
sd = input(true, title="Show Entry Cross After Threshold High or Low")
 
//Williams Acceleration/Deceleration Formula
short_Avg = sma(src, savg)
long_Avg = sma(src, lavg)
 
ao = short_Avg - long_Avg
ac = ao - sma(ao, savg)
 
//upper threshold lines
ach = highest(ac, lb)*pt
acl = lowest(ac, lb)*pt
 
//mid point threshold lines
achm = ach*.50
aclm = acl*.50
 
//4 color histogram
histA_IsUp = ac > ac[1] and ac > 0
histA_IsDown = ac < ac[1] and ac > 0
histB_IsDown = ac < ac[1] and ac <= 0
histB_IsUp = ac > ac[1] and ac <= 0
 
//Warniing Histogram
warn_color = ((ac > achm and ac[1] < achm[1]) or (ac < aclm and ac[1] > aclm[1]))
 
plot_color = histA_IsUp ? aqua : histA_IsDown ? blue : histB_IsDown ? red : histB_IsUp ? maroon : gray
 
//Histogram based on Threshold
col_pr = ac >= ach ? red  : ac <= acl ? green : warn_color ? orange : gray
 
col_Histogram = col_Hist ? col_pr : plot_color
 
cross_down = (ac[3] > ach[3] or ac[4] > ach[4] or ac[5] > ach[5] or ac[6] > ach[6] or ac[7] > ach[7]) and ((sma(ac, 1)[1]) > achm[1] and (sma(ac, 1)) <= achm)
 //or ac[8] > ach[8]
cross_up = (ac[3] < acl[3] or ac[4] < acl[4] or ac[5] < acl[5] or ac[6] < acl[6] or ac[7] < acl[7]) and (sma(ac, 1)[1]) < aclm
 
circleYPosition = achm
circleYPosition_l = aclm
 
plot(ac, title="Williams ADO", style=histogram, linewidth=4, color=col_Histogram)
plot(sl and sma(ac, 1) ? sma(ac, 1) : na, title="Acc/Dec Line", style=line, linewidth=4, color=white)
plot(0, title="0 Line", style=solid, linewidth=3, color=silver)
plot(stl and ach ? ach : na, title="High Threshold Line", style=line, linewidth=4, color=red)
plot(stl and acl ? acl : na, title="Low Threshold Line", style=line, linewidth=4, color=lime)
p1 = plot(stml and achm ? achm : na, title="MidPoint High Threshold Line", style=line, linewidth=2, color=gray)
p2 = plot(stml and aclm ? aclm : na, title="MidPoint Low Threshold Line", style=line, linewidth=2, color=gray)
fill(p1,p2, color=silver, transp=70)
//plot(sd and cross(sma(ac, 1), achm) ? circleYPosition : na,style=cross, linewidth=4, color=aqua)
plot(sd and cross_down and cross(sma(ac, 1), achm) ? circleYPosition : na,style=cross, linewidth=6, color=fuchsia)
plot(sd and cross_up and cross(sma(ac, 1), aclm) ? circleYPosition_l : na,style=cross, linewidth=6, color=yellow)