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")
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.