// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ExpertTraderASK
//@version=6
indicator("Trend Direction Buy/Sell Signals", overlay=true)
// Inputs
fastLength = input.int(20, "Fast EMA", minval=1)
slowLength = input.int(50, "Slow EMA", minval=1)
// EMA Calculations
fastEMA = ta.ema(close, fastLength)
slowEMA = ta.ema(close, slowLength)
// Trend
upTrend = fastEMA > slowEMA
downTrend = fastEMA < slowEMA
// Signals
buySignal = ta.crossover(fastEMA, slowEMA)
sellSignal = ta.crossunder(fastEMA, slowEMA)
// Plot EMAs
plot(fastEMA, color=upTrend ? color.lime : color.red, linewidth=2, title="Fast EMA")
plot(slowEMA, color=color.blue, linewidth=2, title="Slow EMA")
// Buy/Sell Arrows
plotshape(buySignal,
title="Buy",
location=location.belowbar,
color=color.green,
style=shape.labelup,
text="BUY",
textcolor=color.white,
size=size.small)
plotshape(sellSignal,
title="Sell",
location=location.abovebar,
color=color.red,
style=shape.labeldown,
text="SELL",
textcolor=color.white,
size=size.small)
// Background Color
bgcolor(upTrend ? color.new(color.green, 92) : color.new(color.red, 92))
// Alerts
alertcondition(buySignal, title="Buy Alert", message="BUY Signal")
alertcondition(sellSignal, title="Sell Alert", message="SELL Signal")