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

//@version=5
indicator("Colored EMA", overlay = true)
//Will draw an EMA with the specified length and with specific colors depending on 
//whether it's a bullish or bearish trend.


// ––––– Input
ema_length = input.int(defval = 80, title = "EMA Length")
bullishColor = input.color(defval = color.new(color.white, 10), title = "Bullish Color")
bearishColor = input.color(defval = color.red, title = "Bearish Color")


// ––––– Calculations
ema = ta.ema(close, ema_length)
emaColor = ema < close ? bullishColor : bearishColor


// ––––– Visuals
plot(ema, title = "Colored EMA", color = emaColor, linewidth = 2)

