OPEN-SOURCE SCRIPT

Trend-Based Buy/Sell Signals

//version=5
indicator("Trend-Based Buy/Sell Signals", overlay=true)

// Input parameters
ema_short = input(9, title="Short EMA")
ema_long = input(21, title="Long EMA")

// Calculating EMAs
ema1 = ta.ema(close, ema_short)
ema2 = ta.ema(close, ema_long)

// Define buy and sell conditions
buy_condition = ta.crossover(ema1, ema2) // Short EMA crosses above Long EMA
sell_condition = ta.crossunder(ema1, ema2) // Short EMA crosses below Long EMA

// Plot EMAs
plot(ema1, color=color.green, title="Short EMA")
plot(ema2, color=color.red, title="Long EMA")

// Buy and Sell Signals
bgcolor(buy_condition ? color.new(color.green, 90) : na, title="Buy Signal Background")
bgcolor(sell_condition ? color.new(color.red, 90) : na, title="Sell Signal Background")
plotshape(series=buy_condition, style=shape.labelup, color=color.green, location=location.belowbar, title="Buy Signal")
plotshape(series=sell_condition, style=shape.labeldown, color=color.red, location=location.abovebar, title="Sell Signal")

// Basic Trend Visualization
high_line = ta.highest(high, 50)
low_line = ta.lowest(low, 50)
plot(high_line, color=color.blue, linewidth=2, title="High Trend Line")
plot(low_line, color=color.orange, linewidth=2, title="Low Trend Line")

// Alerts
alertcondition(buy_condition, title="Buy Alert", message="Buy Signal Triggered!")
alertcondition(sell_condition, title="Sell Alert", message="Sell Signal Triggered!")
Chart patterns

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer