OPEN-SOURCE SCRIPT

SHIVSHANKAR BIND MACD Crossover

//version=5
indicator("MACD Crossover with Vertical Lines", overlay=true)

// MACD Parameters
fast_length = input(12, title="MACD Fast Length")
slow_length = input(26, title="MACD Slow Length")
signal_length = input(9, title="MACD Signal Length")

// MACD Calculation
[macdLine, signalLine, _] = ta.macd(close, fast_length, slow_length, signal_length)

// MACD Crossover conditions
bullishCrossover = ta.crossover(macdLine, signalLine)
bearishCrossover = ta.crossunder(macdLine, signalLine)

// Plot MACD and Signal lines (not necessary if only vertical lines are required)
plot(macdLine, title="MACD Line", color=color.blue, linewidth=1)
plot(signalLine, title="Signal Line", color=color.orange, linewidth=1)

// Add vertical line on crossover
var line bullLine = na
var line bearLine = na

if (bullishCrossover)
line.delete(bullLine)
bullLine := line.new(bar_index, high, bar_index, low, color=color.green, width=2)
if (bearishCrossover)
line.delete(bearLine)
bearLine := line.new(bar_index, high, bar_index, low, color=color.red, width=2)

// Buy/Sell labels
plotshape(series=bullishCrossover, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=bearishCrossover, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
Moving AveragesTrend Analysis

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer