OPEN-SOURCE SCRIPT
Stochastic + MACD Alignment Signals

//version=5
indicator("Stochastic + MACD Alignment Signals", overlay=true)
// ————— INPUTS —————
stochLength = input.int(14, "Stoch Length")
k = input.int(3, "K Smoothing")
d = input.int(3, "D Smoothing")
macdFast = input.int(12, "MACD Fast Length")
macdSlow = input.int(26, "MACD Slow Length")
macdSignal = input.int(9, "MACD Signal Length")
emaLen = input.int(21, "EMA Filter Length")
// ————— CALCULATIONS —————
// Stochastic
kRaw = ta.stoch(close, high, low, stochLength)
kSmooth = ta.sma(kRaw, k)
dSmooth = ta.sma(kSmooth, d)
// MACD
macd = ta.ema(close, macdFast) - ta.ema(close, macdSlow)
signal = ta.ema(macd, macdSignal)
hist = macd - signal
// EMA Filter
ema = ta.ema(close, emaLen)
// ————— SIGNAL CONDITIONS —————
// BUY CONDITIONS
stochBull = ta.crossover(kSmooth, dSmooth) and kSmooth < 20
macdBull = ta.crossover(macd, signal) or (hist > 0)
emaBull = close > ema
buySignal = stochBull and macdBull and emaBull
// SELL CONDITIONS
stochBear = ta.crossunder(kSmooth, dSmooth) and kSmooth > 80
macdBear = ta.crossunder(macd, signal) or (hist < 0)
emaBear = close < ema
sellSignal = stochBear and macdBear and emaBear
// ————— PLOTTING SIGNALS —————
plotshape(buySignal, title="BUY", style=shape.labelup,
color=color.new(color.green, 0), size=size.large, text="BUY")
plotshape(sellSignal, title="SELL", style=shape.labeldown,
color=color.new(color.red, 0), size=size.large, text="SELL")
// ————— OPTIONAL ALERTS —————
alertcondition(buySignal, title="Buy Signal", message="Stoch + MACD Alignment BUY")
alertcondition(sellSignal, title="Sell Signal", message="Stoch + MACD Alignment SELL")
indicator("Stochastic + MACD Alignment Signals", overlay=true)
// ————— INPUTS —————
stochLength = input.int(14, "Stoch Length")
k = input.int(3, "K Smoothing")
d = input.int(3, "D Smoothing")
macdFast = input.int(12, "MACD Fast Length")
macdSlow = input.int(26, "MACD Slow Length")
macdSignal = input.int(9, "MACD Signal Length")
emaLen = input.int(21, "EMA Filter Length")
// ————— CALCULATIONS —————
// Stochastic
kRaw = ta.stoch(close, high, low, stochLength)
kSmooth = ta.sma(kRaw, k)
dSmooth = ta.sma(kSmooth, d)
// MACD
macd = ta.ema(close, macdFast) - ta.ema(close, macdSlow)
signal = ta.ema(macd, macdSignal)
hist = macd - signal
// EMA Filter
ema = ta.ema(close, emaLen)
// ————— SIGNAL CONDITIONS —————
// BUY CONDITIONS
stochBull = ta.crossover(kSmooth, dSmooth) and kSmooth < 20
macdBull = ta.crossover(macd, signal) or (hist > 0)
emaBull = close > ema
buySignal = stochBull and macdBull and emaBull
// SELL CONDITIONS
stochBear = ta.crossunder(kSmooth, dSmooth) and kSmooth > 80
macdBear = ta.crossunder(macd, signal) or (hist < 0)
emaBear = close < ema
sellSignal = stochBear and macdBear and emaBear
// ————— PLOTTING SIGNALS —————
plotshape(buySignal, title="BUY", style=shape.labelup,
color=color.new(color.green, 0), size=size.large, text="BUY")
plotshape(sellSignal, title="SELL", style=shape.labeldown,
color=color.new(color.red, 0), size=size.large, text="SELL")
// ————— OPTIONAL ALERTS —————
alertcondition(buySignal, title="Buy Signal", message="Stoch + MACD Alignment BUY")
alertcondition(sellSignal, title="Sell Signal", message="Stoch + MACD Alignment SELL")
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.