OPEN-SOURCE SCRIPT

Two MA Crossover with Labels

153
//version=5
indicator("Two MA Crossover with Labels", overlay=true)

// === Input Parameters ===
shortPeriod = input.int(10, title="Short MA Period")
longPeriod = input.int(100, title="Long MA Period")

// === Moving Averages ===
shortMA = ta.sma(close, shortPeriod)
longMA = ta.sma(close, longPeriod)

// === Plotting MAs ===
plot(shortMA, color=color.orange, title="Short MA")
plot(longMA, color=color.blue, title="Long MA")

// === Crossover Conditions ===
bullishCross = ta.crossover(shortMA, longMA)
bearishCross = ta.crossunder(shortMA, longMA)

// === Labels ===
if bullishCross
label.new(bar_index, low, "Buy", style=label.style_label_up, color=color.green, textcolor=color.white)

if bearishCross
label.new(bar_index, high, "Sell", style=label.style_label_down, color=color.red, textcolor=color.white)

免責聲明

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