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")

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。