KAMIKAMI EMA RIBBON
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@ CryptoFilio 2021-2022
//@version=5
indicator('CF - KAMIKAMI EMA RIBBON', overlay=true, timeframe="", timeframe_gaps=false)

//************************** Inputs ****************************//

turnonfill1 = input.bool(true, title="Turn on colored fill between EMA1 and EMA 2?")
turnonfill2 = input.bool(true, title="Turn on colored fill between EMA2 and EMA 3?")
turnonfill3 = input.bool(true, title="Turn on colored fill between EMA1 and EMA 3?")

lenemaS = input.int  (21, minval   = 3 , title='Short EMA Length')
srcemaS = input      (close, title =           'Short EMA Source')
outS    = ta.ema     (srcemaS, lenemaS)

lenemaM = input.int  (50, minval   = 5 , title='Medium EMA Length')
srcemaM = input      (close, title =           'Medium EMA Source')
outM    = ta.ema     (srcemaM, lenemaM)

lenemaL   = input.int(200, minval  = 8 , title='Long EMA Length')
srcemaL   = input    (close,     title =       'Long EMA Source')
outL      = ta.ema   (srcemaL, lenemaL)
//EMA

EMAS = outS
EMAM = outM
EMAL = outL

EMAS_color = EMAS > close ? #EE4B2B : #AFE1AF
EMAM_color = EMAM > close ? #AA4A44 : #5F9EA0
EMAL_color = EMAL > close ? #880808 : #097969

lowaboveEMAS  = low  >  EMAS
lowaboveEMAM  = low  >  EMAM
lowaboveEMAL  = low  >  EMAL

lowbelowEMAS  = low  <  EMAS
lowbelowEMAM  = low  <  EMAM
lowbelowEMAL  = low  <  EMAL

highaboveEMAS = high >  EMAS
highaboveEMAM = high >  EMAM
highaboveEMAL = high >  EMAL

highbelowEMAS = high <  EMAS
highbelowEMAM = high <  EMAM
highbelowEMAL = high <  EMAL

BullBounceS = lowaboveEMAS [1] and lowbelowEMAS  and close > EMAS  // and close > open
BearBounceS = highbelowEMAS[1] and highaboveEMAS and close < EMAS  //and close < open

BullBounceM = lowaboveEMAM [1] and lowbelowEMAM  and close > EMAM  // and close > open
BearBounceM = highbelowEMAM[1] and highaboveEMAM and close < EMAM  //and close < open

BullBounceL = lowaboveEMAL [1] and lowbelowEMAL  and close > EMAL  // and close > open
BearBounceL = highbelowEMAL[1] and highaboveEMAL and close < EMAL  //and close < open

plots = plot(EMAS, title='The EMA Short',  color = EMAS_color, linewidth=2)
plotm = plot(EMAM, title='The EMA Medium', color = EMAM_color, linewidth=2)
plotl = plot(EMAL, title='The EMA Long',   color = EMAL_color, linewidth=2)

fill(plots,plotm, color = turnonfill1 ? color.new(EMAL_color, 30):color.new(EMAL_color, 100) )
fill(plotm,plotl, color = turnonfill2 ? color.new(EMAL_color, 30):color.new(EMAL_color, 100) )
fill(plots,plotl, color = turnonfill3 ? color.new(EMAL_color, 30):color.new(EMAL_color, 100) )

plotshape(BullBounceS, color = color.green, style=shape.arrowup  , size=size.small, location=location.belowbar, editable=false)
plotshape(BearBounceS, color = color.red,   style=shape.arrowdown, size=size.small, location=location.abovebar, editable=false)
plotshape(ta.crossover(EMAS,EMAM), color =color.new (color.green, 30), style=shape.diamond, size=size.small, location=location.bottom, editable=false)
plotshape(ta.crossunder(EMAS,EMAM), color=color.new (color.red, 30),   style=shape.diamond, size=size.small, location=location.bottom, editable=false)
plotshape(ta.crossover(EMAM,EMAL), color =color.new (color.green, 50), style=shape.diamond, size=size.small, location=location.bottom, editable=false)
plotshape(ta.crossunder(EMAM,EMAL), color=color.new (color.red, 50),style=shape.diamond, size=size.small, location=location.bottom, editable=false)
plotshape(ta.crossover(EMAS,EMAL), color =color.new (color.green, 70), style=shape.diamond, size=size.small, location=location.bottom, editable=false)
plotshape(ta.crossunder(EMAS,EMAL), color=color.new (color.red, 70), style=shape.diamond, size=size.small, location=location.bottom, editable=false)

//BUY  = (BullBounce or out50 > ohlc4) and ohlc4 > out
//SELL = (BearBounce or out50 < ohlc4) and ohlc4 < out