Mac D Strategy *Free*

//@version=5
strategy(“MACD Strategy”, overlay=true)

// Define MACD parameters
fastLength = input.int(12, title=”Fast Length”)
slowLength = input.int(26, title=”Slow Length”)
signalSmoothing = input.int(9, title=”Signal Smoothing”)

// Calculate MACD and Signal Line
[macdLine, signalLine, _] = ta.macd(close, fastLength, slowLength, signalSmoothing)

// Plot MACD and Signal Line
plot(macdLine, color=color.blue, title=”MACD Line”)
plot(signalLine, color=color.orange, title=”Signal Line”)

// Define Buy and Sell conditions
buyCondition = ta.crossover(macdLine, signalLine)
sellCondition = ta.crossunder(macdLine, signalLine)

// Plot Buy and Sell signals on the chart
plotshape(series=buyCondition, location=location.belowbar, color=color.green, style=shape.labelup, title=”Buy Signal”)
plotshape(series=sellCondition, location=location.abovebar, color=color.red, style=shape.labeldown, title=”Sell Signal”)

// Execute Buy and Sell orders
if (buyCondition)
strategy.entry(“Buy”, strategy.long)

if (sellCondition)
strategy.entry(“Sell”, strategy.short)