OPEN-SOURCE SCRIPT
Two MA Crossover with Labels

//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)
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)
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.