RicardoSantos

[RS]Murrey's Math Lines Channel V1

EXPERIMENTAL:MML using a absolute deviation average oscilator, i think this gives better results then donchian channels.
color scheme for the bar color was ripped from UCS's MML oscilator :p thx.
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?
study("[RS]Murrey's Math Lines Channel Adaptation V1", overlay=true)
useHA = input(false, title="Use Heikken Ashi Candles Source:")
price_src = input(close, title="Price Source:")
price = useHA ? security(heikenashi(tickerid), period, price_src) : price_src
l1 = input(1, title="Deviation Factor:")
//  ||----------------------------------------------------------------------------------------------------------------------------||
//  ||---   Utility Functions:
//  ||----------------------------------------------------------------------------------------------------------------------------||
capdev()=> cum(stdev(close, 4))/(n+1)
oscdev(src, multiplier)=>
    pre = nz(output[1], src)
    output = src-capdev()*multiplier > pre ? pre + capdev() : src+capdev()*multiplier < pre ? pre - capdev() : pre
//  ||----------------------------------------------------------------------------------------------------------------------------||
//  ||---   Channel Calculation:
//  ||----------------------------------------------------------------------------------------------------------------------------||
ML = oscdev(price, l1)
//  ||---   Upper Band Lines:
UML1 = ML +  capdev() *  l1
UML2 = ML + (capdev() * (l1*2))
UML3 = ML + (capdev() * (l1*3))
UML4 = ML + (capdev() * (l1*4))
UML5 = ML + (capdev() * (l1*5))
UML6 = ML + (capdev() * (l1*6))
//  ||---   Lower Band Lines:
LML1 = ML -  capdev() *  l1
LML2 = ML - (capdev() * (l1*2))
LML3 = ML - (capdev() * (l1*3))
LML4 = ML - (capdev() * (l1*4))
LML5 = ML - (capdev() * (l1*5))
LML6 = ML - (capdev() * (l1*6))
//  ||---   Output Lines:
plot(ML,    color=black,    linewidth=2,    title="ML")
//  ||---   Output Upper Band Lines:
plot(UML1,  color=black,    linewidth=1,    title="UML 1")
plot(UML2,  color=gray,     linewidth=1,    title="UML 2")
plot(UML3,  color=silver,   linewidth=1,    title="UML 3")
plot(UML4,  color=blue,     linewidth=2,    title="UML 4")
plot(UML5,  color=navy,     linewidth=1,    title="UML 5")
plot(UML6,  color=black,    linewidth=1,    title="UML 6")
//  ||---   Output Lower Band Lines:
plot(LML1,  color=black,    linewidth=1,    title="LML 1")
plot(LML2,  color=gray,     linewidth=1,    title="LML 2")
plot(LML3,  color=silver,   linewidth=1,    title="LML 3")
plot(LML4,  color=blue,     linewidth=2,    title="LML 4")
plot(LML5,  color=navy,     linewidth=1,    title="LML 5")
plot(LML6,  color=black,    linewidth=1,    title="LML 6")
//  ||----------------------------------------------------------------------------------------------------------------------------||
//  ||---   Buy and Sell Signals:
//  ||----------------------------------------------------------------------------------------------------------------------------||

sell0   = price[1] >= ML[1] and price < ML ? true : false
buy0    = price[1] <= ML[1] and price > ML ? true : false

plotshape(sell0, style=shape.triangledown,  location=location.abovebar, color=maroon)
plotshape(buy0,  style=shape.triangleup,    location=location.belowbar, color=green)

showBG = input(false)
bgcolor(not showBG ? na : sell0 ? maroon : na, 70)
bgcolor(not showBG ? na : buy0  ? green  : na, 70)

//  ||----------------------------------------------------------------------------------------------------------------------------||
//  ||---   UCS's MMLO Bar Color Scheme:    --------------------------------------------------------------------------------------||
//  ||----------------------------------------------------------------------------------------------------------------------------||
a = price > ML and price < UML1
b = price > ML and price < UML2
c = price > ML and price < UML3
d = price > ML and price < UML4

z = price < ML and price > LML1
y = price < ML and price > LML2
x = price < ML and price > LML3
w = price < ML and price > LML4

showBarColor = input(true, title="Display Candle Colors:")
colordef = a ? #ADFF2F : b ? #32CD32 : c ? #3CB371 : d ? #008000 : z ? #CD5C5C : y ? #FA8072 : x ? #FFA07A : w ? #FF0000 : blue
barcolor(not showBarColor ? na : colordef)
//  ||----------------------------------------------------------------------------------------------------------------------------||
//  ||----------------------------------------------------------------------------------------------------------------------------||