OPEN-SOURCE SCRIPT

JW Clean Adaptive Channel

81
//version=5
indicator("JW Clean Adaptive Channel", overlay=true)

// Inputs
emaFast = input.int(20, "EMA Fast")
emaMid = input.int(50, "EMA Mid")
emaSlow = input.int(200, "EMA Slow")
atrLen = input.int(14, "ATR Length")
regLen = input.int(100, "Regression Window")
multATR = input.float(2.0, "Channel Width x ATR", step=0.1)
baseATR = input.int(50, "ATR Baseline")
volCap = input.float(2.5, "Max Vol Mult", step=0.1)

// EMAs
ema20 = ta.ema(close, emaFast)
ema50 = ta.ema(close, emaMid)
ema200 = ta.ema(close, emaSlow)
plot(ema20, "EMA 20", color=color.lime)
plot(ema50, "EMA 50", color=color.yellow)
plot(ema200, "EMA 200", color=color.orange, linewidth=2)

// Adaptive regression channel
atr = ta.atr(atrLen)
bAtr = ta.sma(atr, baseATR)
vRat = bAtr == 0.0 ? 1.0 : math.min(atr / bAtr, volCap)
width = atr * multATR * vRat
basis = ta.linreg(close, regLen, 0)
upper = basis + width
lower = basis - width
slope = basis - basis[1]
chanColor = slope > 0 ? color.lime : slope < 0 ? color.red : color.gray

pU = plot(upper, "Upper", color=chanColor)
pL = plot(lower, "Lower", color=chanColor)
pB = plot(basis, "Basis", color=color.gray)
fill(pU, pL, color=color.new(chanColor, 85))

// Candle and background color
ribbonBull = ema20 > ema50 and ema50 > ema200
ribbonBear = ema20 < ema50 and ema50 < ema200
barcolor(ribbonBull ? color.lime : ribbonBear ? color.red : na)
bgcolor(slope > 0 ? color.new(color.green, 85) : slope < 0 ? color.new(color.red, 85) : na)

// MACD buy/sell markers
[macdLine, sigLine, _] = ta.macd(close, 12, 26, 9)
buySig = ta.crossover(macdLine, sigLine) and slope > 0
sellSig = ta.crossunder(macdLine, sigLine) and slope < 0
plotshape(buySig, title="Buy", style=shape.triangleup, color=color.lime, location=location.belowbar, size=size.tiny)
plotshape(sellSig, title="Sell", style=shape.triangledown, color=color.red, location=location.abovebar, size=size.tiny)

// Trend strength label (single-line calls; no dangling commas)
strength = slope * vRat * 1000.0
string tText = "Sideways"
color tCol = color.gray
if strength > 2
tText := "Strong Uptrend"
tCol := color.lime
else if strength > 0.5
tText := "Weak Uptrend"
tCol := color.new(color.lime, 40)
else if strength < -2
tText := "Strong Downtrend"
tCol := color.red
else if strength < -0.5
tText := "Weak Downtrend"
tCol := color.new(color.red, 40)

var label tLbl = na
if barstate.islast
if not na(tLbl)
label.delete(tLbl)
tLbl := label.new(x=bar_index, y=high, text=tText, style=label.style_label_right, textcolor=color.white, color=tCol, size=size.normal, yloc=yloc.price)

// 10-day breakout alerts
hi10 = ta.highest(high, 10)
lo10 = ta.lowest(low, 10)
alertcondition(close > hi10, title="10-Day High Break", message="{{ticker}} 10D HIGH @ {{close}}")
alertcondition(close < lo10, title="10-Day Low Break", message="{{ticker}} 10D LOW @ {{close}}")
alertcondition(buySig, title="Buy Alert", message="BUY {{ticker}} @ {{close}}")
alertcondition(sellSig, title="Sell Alert", message="SELL {{ticker}} @ {{close}}")

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.