OPEN-SOURCE SCRIPT

MA & EMA Crossover

//version=5
indicator("MA & EMA Crossover", overlay=true)

// Input Parameters
ma_length = input.int(20, title="MA Length", minval=1)
ema_length = input.int(10, title="EMA Length", minval=1)

// Calculations
ma = ta.sma(close, ma_length)
ema = ta.ema(close, ema_length)

// Signal Conditions
buy_signal = ta.crossover(ema, ma) // EMA crosses above MA
sell_signal = ta.crossunder(ema, ma) // EMA crosses below MA

// Plot MA and EMA
plot(ma, color=color.blue, title="MA (20)", linewidth=2)
plot(ema, color=color.red, title="EMA (10)", linewidth=2)

// Buy and Sell Signals
plotshape(series=buy_signal, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal", text="BUY")
plotshape(series=sell_signal, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal", text="SELL")

// Alerts
alertcondition(buy_signal, title="Buy Alert", message="EMA crossed above MA - Buy Signal")
alertcondition(sell_signal, title="Sell Alert", message="EMA crossed below MA - Sell Signal")
crossoverExponential Moving Average (EMA)

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