Pine Script (TradingView)
This is a TradingView Pine Script example for this indicator. Paste it into the TradingView Pine Editor, add it to your chart, and adjust inputs for your market and timeframe.
//@version=6
strategy("MACD β Moving Average Convergence Divergence", overlay=true)
fast = input.int(12, "Fast")
slow = input.int(26, "Slow")
sig = input.int(9, "Signal")
[macdLine, signalLine, _] = ta.macd(close, fast, slow, sig)
longSignal = ta.crossover(macdLine, signalLine)
shortSignal = ta.crossunder(macdLine, signalLine)
if longSignal
strategy.entry("Long", strategy.long)
if shortSignal
strategy.close("Long")
plot(macdLine, "MACD", color=color.teal)
plot(signalLine, "Signal", color=color.orange)