OPEN-SOURCE SCRIPT

EMA Buy/Sell Signals

55
//version=5
indicator("EMA Buy/Sell Signals", overlay=true)

// Calculate the 20-period EMA on the 1-hour chart
ema20 = request.security(syminfo.tickerid, "60", ta.ema(close, 20))

// Calculate the 10-period EMA on the 3-minute chart
ema10 = ta.ema(close, 10)

// Determine the bias based on the 1-hour chart
var float bias = na
if (ema20 != na)
bias := close > ema20 ? 1 : -1

// Identify entry signals on the 3-minute chart
longCondition = (bias == 1) and ta.crossover(close, ema10)
shortCondition = (bias == -1) and ta.crossunder(close, ema10)

// Plot signals on the chart
plotshape(series=longCondition, location=location.belowbar, color=color.green, style=shape.labelup, text="Buy")
plotshape(series=shortCondition, location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell")

// Plot EMA lines on the chart
plot(ema20, title="EMA 20", color=color.blue)
plot(ema10, title="EMA 10", color=color.orange)

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.