//version=5 indicator("Buy and Sell Indicator with Bar Labels", overlay=true)
// Define short and long period for moving averages shortPeriod = input.int(9, title="Short Period SMA") longPeriod = input.int(21, title="Long Period SMA")
// Plot the moving averages plot(shortSMA, color=color.blue, linewidth=2, title="Short Period SMA") plot(longSMA, color=color.red, linewidth=2, title="Long Period SMA")
// Generate Buy and Sell signals based on crossover buySignal = ta.crossover(shortSMA, longSMA) sellSignal = ta.crossunder(shortSMA, longSMA)
// Create labels for buy and sell signals on bars if buySignal label.new(bar_index, low, "BUY", style=label.style_label_up, color=color.green, textcolor=color.white, size=size.small, yloc=yloc.belowbar)
if sellSignal label.new(bar_index, high, "SELL", style=label.style_label_down, color=color.red, textcolor=color.white, size=size.small, yloc=yloc.abovebar)
// Add alerts for Buy and Sell signals alertcondition(buySignal, title="Buy Signal Alert", message="Buy Signal Triggered!") alertcondition(sellSignal, title="Sell Signal Alert", message="Sell Signal Triggered!")