T3 Super Guppy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © waifuGod

//@version=5
indicator(title = "T3 Super Guppy",shorttitle = "T3SuperGuppy by WaifuMaxi" ,overlay = true)
// # ============================ Inputs ============================================ #
dis_type    = input.string("Compact",title = "Display Type", options = ["Compact","Full"], tooltip ="Compact will only show half the t3 MA, but dosent affect calculation")
const       = input.float(0.7,title = "Constant")
show1       = input.bool(defval = false , title = "show only one colour", tooltip = "to make colour constant, uses base colour", group = "colour settings") 
upCol       = input.color(#205bfc,title ="T3 Up Trend Colour",group ="colour settings")
downCol     = input.color(#f12838,title ="T3 Down Trend Colour",group ="colour settings")
baseCol     = input.color(#e91e63,title ="T3 Base Colour",group ="colour settings")
source      = close

// # ========================== Functions =========================================== #
t3_calc(_src, _len, _const) =>
    ema1 = ta.ema(_src, _len)
    ema2 = ta.ema(ema1, _len)
    ema3 = ta.ema(ema2, _len)
    ema4 = ta.ema(ema3, _len)
    ema5 = ta.ema(ema4, _len)
    ema6 = ta.ema(ema5, _len)
    b = _const
    c1 = -b * b * b
    c2 = 3 * b * b + 3 * b * b * b
    c3 = -6 * b * b - 3 * b - 3 * b * b * b
    c4 = 1 + 3 * b + b * b * b + 3 * b * b
    T3_val = c1 * ema6 + c2 * ema5 + c3 * ema4 + c4 * ema3
    T3_val
// use to calculate transparency step based on display type
transp_multi(_step)=>
    step = dis_type == "Compact" ? _step : _step + 1
    stepVal = dis_type == "Compact" ? 5 : 2
    mltp = 100 - (step  * stepVal)
    tval = mltp < 0 ? 100 : mltp
    tval
// to calculate crosses to determine colour gradienti
colour_step(_arr)=>
    counter = 0
    for i = 0 to (array.size(id = _arr) - 2)
        bool c_type = array.get(_arr, i) > array.get(_arr,i + 1)
        if c_type
            counter := counter + 1
        
    counter
// # ========================== T3 MA =============================================== #
// fast t3
T1    = t3_calc(source, 3,const)
T2    = t3_calc(source, 6,const)
T3    = t3_calc(source, 9,const)
T4    = t3_calc(source, 12,const)
T5    = t3_calc(source, 15,const)
T6    = t3_calc(source, 18,const)
T7    = t3_calc(source, 21,const)
// slow t3
T8    = t3_calc(source, 24,const)
T9    = t3_calc(source, 27,const)
T10   = t3_calc(source, 30,const)
T11   = t3_calc(source, 33,const)
T12   = t3_calc(source, 36,const)
T13   = t3_calc(source, 39,const)
T14   = t3_calc(source, 42,const)
T15   = t3_calc(source, 45,const)
T16   = t3_calc(source, 48,const)
T17   = t3_calc(source, 51,const)
T18   = t3_calc(source, 54,const)
T19   = t3_calc(source, 57,const)
T20   = t3_calc(source, 60,const)

// # ========================== arrays to store t3 vals ========================================= #
T3Arr = array.from(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20) 

// # ========================== Colour Rules ========================================= #
t_val = colour_step(T3Arr)
col_g = color.from_gradient(value = t_val, bottom_value = 0 , top_value = 19 , bottom_color = downCol, top_color = upCol) 
finalCol = show1 ? baseCol :  col_g

// # ===========================  Plots =============================================== #
bool plotBool = dis_type == "Compact"
// fast
t1l =plot(T1, color=color.new(finalCol,98), editable = false )
t2l =plot(T2, color=color.new(finalCol,98), editable = false)
t3l =plot(T3, color=color.new(finalCol,transp_multi(1)), editable = false)
t4l =plot(T4, color=color.new(finalCol,transp_multi(2)), editable = false)
t5l =plot(T5, color=color.new(finalCol,transp_multi(3)), editable = false)
t6l =plot(T6, color=color.new(finalCol,transp_multi(4)), editable = false)
t7l =plot(T7, color=color.new(finalCol,transp_multi(5)), editable = false)
//slow
t8l =plot(T8, color=color.new(finalCol,transp_multi(6)), editable = false)
t9l =plot(T9, color=color.new(finalCol,transp_multi(7)), editable = false)
t10l=plot(T10, color=color.new(finalCol,transp_multi(8)), editable = false)
t11l =plot(plotBool ? na : T11, color=color.new(finalCol,transp_multi(9)), editable = false)
t12l =plot(plotBool ? na : T12, color=color.new(finalCol,transp_multi(10)), editable = false)
t13l =plot(plotBool ? na : T13, color=color.new(finalCol,transp_multi(11)), editable = false)
t14l =plot(plotBool ? na : T14, color=color.new(finalCol,transp_multi(12)), editable = false)
t15l =plot(plotBool ? na : T15, color=color.new(finalCol,transp_multi(13)), editable = false)
t16l =plot(plotBool ? na : T16, color=color.new(finalCol,transp_multi(14)), editable = false)
t17l =plot(plotBool ? na : T17, color=color.new(finalCol,transp_multi(15)), editable = false)
t18l =plot(plotBool ? na : T18, color=color.new(finalCol,transp_multi(16)), editable = false)
t19l =plot(plotBool ? na : T19, color=color.new(finalCol,transp_multi(17)), editable = false)
t20l =plot(plotBool ? na : T20, color=color.new(finalCol,transp_multi(18)), editable = false)

// # =========================== Fills =============================================== #
fill(t1l,t2l, color.new(finalCol,98))
fill(t2l,t3l, color.new(finalCol,transp_multi(1)))
fill(t3l,t4l, color.new(finalCol,transp_multi(2)))
fill(t4l,t5l, color.new(finalCol,transp_multi(3)))
fill(t5l,t6l, color.new(finalCol,transp_multi(4)))
fill(t6l,t7l, color.new(finalCol,transp_multi(5)))
fill(t7l,t8l, color.new(finalCol,transp_multi(6)))
fill(t8l,t9l, color.new(finalCol,transp_multi(7)))
fill(t9l,t10l, color.new(finalCol,transp_multi(8)))
fill(t10l,t11l, color.new(finalCol,transp_multi(9)))
fill(t11l,t12l, color.new(finalCol,transp_multi(10)))
fill(t12l,t13l, color.new(finalCol,transp_multi(11)))
fill(t13l,t14l, color.new(finalCol,transp_multi(12)))
fill(t14l,t15l, color.new(finalCol,transp_multi(13)))
fill(t15l,t16l, color.new(finalCol,transp_multi(14)))
fill(t16l,t17l, color.new(finalCol,transp_multi(15)))
fill(t17l,t18l, color.new(finalCol,transp_multi(16)))
fill(t18l,t19l, color.new(finalCol,transp_multi(17)))
fill(t19l,t20l, color.new(finalCol,transp_multi(18)))