OPEN-SOURCE SCRIPT

Moving Average Simple

46
//version=5
indicator("EMA 20 and 200 Crossover Strategy", overlay=true)

// Input parameters
emaShortLength = input.int(20, title="Short EMA Length", minval=1)
emaLongLength = input.int(200, title="Long EMA Length", minval=1)

// Calculate EMAs
emaShort = ta.ema(close, emaShortLength) // 20-period EMA
emaLong = ta.ema(close, emaLongLength) // 200-period EMA

// Plot EMAs
plot(emaShort, color=color.blue, title="EMA 20", linewidth=2)
plot(emaLong, color=color.red, title="EMA 200", linewidth=2)

// Crossover Conditions
buySignal = ta.crossover(emaShort, emaLong) // EMA 20 crosses above EMA 200
sellSignal = ta.crossunder(emaShort, emaLong) // EMA 20 crosses below EMA 200

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

// Alerts
alertcondition(buySignal, title="Buy Signal Alert", message="EMA 20 crossed above EMA 200: Buy Signal")
alertcondition(sellSignal, title="Sell Signal Alert", message="EMA 20 crossed below EMA 200: Sell Signal")

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.