Magic Trend By Market Mindset - Zero To Endless
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © marketmindset

//ChangeLog
//v2.0
//Added Timeframe gaps

//v3.0
//Added Magic Fill
//Changed default Line Width

//v4.0
//Bug Fixes

//@version=5
indicator('Magic Trend By Market Mindset - Zero To Endless', 'MT-Z2E', overlay=true, format=format.price, precision=2, timeframe='', timeframe_gaps = false)

src     = input(close, 'CCI Source')
period  = input(21, 'CCI period')
AP      = input(14, 'ATR Period')
mult1   = input.float(1.5, 'ATR Multiplier #1',-5,5,0.25 )
mult2   = input.float(3.0 , 'ATR Multiplier #2',-5,5,0.25 )

ATR     = ta.atr(AP)

cci     = ta.cci(src, period)
mt(coff) =>
    upT = hl2 - ATR * coff
    downT = hl2 + ATR * coff

    MagicTrend = 0.
    MagicTrend := cci >= 0 ? upT < nz(MagicTrend[1]) ? nz(MagicTrend[1]) : upT : downT > nz(MagicTrend[1]) ? nz(MagicTrend[1]) : downT
    MagicTrend

MagicTrend1 = mt(mult1)
MagicTrend2 = mt(mult2)

Color   = cci >= 0 ? #0000FF : #FF0000

MT1     = plot(MagicTrend1, color=Color, linewidth=2)
MT2     = plot(MagicTrend2, color=Color, linewidth=1)

cond    = (MagicTrend1 > MagicTrend2 and cci >= 0) or (MagicTrend1 < MagicTrend2 and cci <= 0)
fill(MT1, MT2, color = cond ? color.new(Color, 75) : na,  title = "Magic Fill")