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")
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。