OPEN-SOURCE SCRIPT

雙均線交叉交易策略 (適用免費版)

59
//version=5
indicator("雙均線交叉交易策略 (適用免費版)", overlay=true)

// === 設定均線參數 ===
shortLength = input(20, title="短期均線 (EMA20)")
longLength = input(50, title="長期均線 (EMA50)")

// === 計算均線 ===
shortEMA = ta.ema(close, shortLength)
longEMA = ta.ema(close, longLength)

// === 交叉訊號 ===
longCondition = ta.crossover(shortEMA, longEMA) // 黃金交叉 (買入)
shortCondition = ta.crossunder(shortEMA, longEMA) // 死亡交叉 (賣出)

// === 畫出買賣訊號箭頭 ===
plot(shortEMA, title="短期 EMA (20)", color=color.blue, linewidth=2)
plot(longEMA, title="長期 EMA (50)", color=color.red, linewidth=2)

plotshape(series=longCondition, location=location.belowbar, color=color.green, style=shape.labelup, title="買入信號")
plotshape(series=shortCondition, location=location.abovebar, color=color.red, style=shape.labeldown, title="賣出信號")

免責聲明

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