Trendicator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dannhau2

//@version=5
indicator("Trendicator", overlay = true)

EMABuy = ta.ema(close,1)
EMASell = ta.ema(open,1)
EMA = ta.ema(input(ohlc4,"Moving Average Source"),input(20,"Moving Average Length"))

var col = color.new(color.black,transp=50)

Buy1 = EMABuy>EMA
Buy2 = EMASell>EMA
Sell1 = EMASell<EMA
Sell2 = EMABuy<EMA

if Buy1 and Buy2
    col := color.new(color.lime,transp=0)

if Sell1 and Sell2
    col := color.new(color.red,transp=0)

p=plot(EMA, "Moving Average", color = col, linewidth=3)
q=plot(close,color=color.new(color.black,transp=100))
fill(p, q, color= Buy1 and Buy2 ? color.new(color.lime,70):color.new(color.red,100))
fill(p, q, color= Sell1 and Sell2 ? color.new(color.red,70):color.new(color.lime,100))

alertcondition(Buy1 and Buy2, title="Uptrend", message="Buy")
alertcondition(Sell1 and Sell2, title="Downtrend", message="Sell")
