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

//@version=4
study("Candle EMA", shorttitle="Candema", overlay=false)

ema3  = ema(close, input( 3        , title="Length 1" ))
ema5  = ema(close, input( 5        , title="Length 2" ))
ema8  = ema(close, input( 8        , title="Length 3" ))
ema13 = ema(close, input(13        , title="Length 4" ))
c_up  = input(color.new(#26a69a, 0), title="color up"  )
c_dn  = input(color.new(#ef5350, 0), title="color down")

max   = max(ema3, ema5, ema8, ema13)
min   = min(ema3, ema5, ema8, ema13)
ope   = 0.
ope  := 
 (ema3 == max or ema3 == min) and (ema5  == max or ema5  == min) ? ema13 : 
 (ema3 == max or ema3 == min) and (ema8  == max or ema8  == min) ? ema13 : 
 (ema3 == max or ema3 == min) and (ema13 == max or ema13 == min) ? ema8  : 
 (ema3 == max or ema3 == min) and (ema8  == max or ema8  == min) ? ema13 : 
 (ema5 == max or ema5 == min) and (ema8  == max or ema8  == min) ? ema13 : 
 (ema5 == max or ema5 == min) and (ema13 == max or ema13 == min) ? ema8  : 
                                                                   ema5   
clo   = 0.
clo  := 
 (ema3 == max or ema3 == min) and (ema5  == max or ema5  == min) ? ema8  : 
 (ema3 == max or ema3 == min) and (ema8  == max or ema8  == min) ? ema5  : 
 (ema3 == max or ema3 == min) and (ema13 == max or ema13 == min) ? ema5  : 
 (ema3 == max or ema3 == min) and (ema8  == max or ema8  == min) ? ema5  : 
 (ema5 == max or ema5 == min) and (ema8  == max or ema8  == min) ? ema3  : 
 (ema5 == max or ema5 == min) and (ema13 == max or ema13 == min) ? ema3  : 
                                                                   ema3   

plotcandle(ope, max, min, clo, title="", color=clo >= ope ? c_up : c_dn, wickcolor=clo >= ope ? c_up : c_dn, bordercolor=clo >= ope ? c_up : c_dn)
