RedK TrendBeads: 3 x MA Crossover Signal with Preset Templates
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RedKTrader

//@version=5
indicator('RedK TrendBeads', shorttitle='K-TrendBeads v1.0', overlay=true, timeframe='', timeframe_gaps=false)

// ---------------------------------------------------------------------------------------------------------------
// 3 MA-Line Ribbon on a slow MA filter line.. just a super simple set-up
//==============================================================================
// updated this version of LazyLine() to reflect a regular WMA for length < 5 
f_LazyLine(_data, _length) =>
    w1 = 0,     w2 = 0,     w3 = 0
    L1 = 0.0,   L2 = 0.0,   L3 = 0.0
    w = _length / 3

    if _length > 4
        w2 := math.round(w)
        w1 := math.round((_length - w2) / 2)
        w3 := int((_length - w2) / 2)

        L1 := ta.wma(_data, w1)
        L2 := ta.wma(L1, w2)
        L3 := ta.wma(L2, w3)
        
    else
        L3 := ta.wma(_data, _length)
        
    L3
//==============================================================================

// =============================================================================    
f_getMA(source, length, type) =>
    type == "SMA" ? ta.sma(source, length) : 
      type == "EMA" ? ta.ema(source, length) :
      type == "WMA" ? ta.wma(source, length) :
      type == "HMA" ? ta.hma(source, length) :
      f_LazyLine(source, length)
// =============================================================================    


// ------------------------------------------------------------------------------------------------
// Inputs
// ------------------------------------------------------------------------------------------------

grp_p = 'Use Preset MA Templates or Manually Customize Values'
grp_m = 'Price Proxy & MA Lines :'
grp_f = 'Filter MA :'

pset_1 = 'RedK_1: 8RSS / 15RSS / 21RSS / 30SMA'
pset_2 = 'RedK_2: 5WMA / 10SMA / 20SMA / 40SMA'
pset_3 = 'SWNG_1: 7EMA / 21EMA / 30EMA / 50SMA'
pset_4 = 'SWNG_2: 10EMA / 21EMA / 50SMA / 100SMA'
pset_5 = 'SWNG_3: 10EMA / 21EMA / 100SMA / 200SMA'

presets = input.bool(false, title = "Use Presets?", inline = 'presets', group = grp_p)
s_preset = input.string(pset_1, title = "", inline = 'presets', group = grp_p,  
  options = [pset_1, pset_2, pset_3, pset_4, pset_5])

Proxy_Src    = input.source(close,   title='Proxy Source',          inline = 'Proxy', group = grp_m)
Proxy_Length = input.int(8,          title = 'Length',   minval = 1, inline = 'Proxy', group = grp_m)
Proxy_Type   = input.string('RSS_WMA', title = 'Type',                    inline = 'Proxy',
  options = ['RSS_WMA', 'WMA', 'EMA', 'SMA', 'HMA'], group = grp_m)

Fast_Src    = input.source(close,   title='Fast MA Source',          inline = 'Fast', group = grp_m)
Fast_Length = input.int(15,          title = 'Length',   minval = 1, inline = 'Fast', group = grp_m)
Fast_Type   = input.string('RSS_WMA', title = 'Type',                    inline = 'Fast',
  options = ['RSS_WMA', 'WMA', 'EMA', 'SMA', 'HMA'], group = grp_m)

Slow_Src    = input.source(close,    title='Slow MA Source',         inline = 'Slow', group = grp_m)
Slow_Length = input.int(21,          title='Length',     minval = 1, inline = 'Slow', group = grp_m)
Slow_Type   = input.string('RSS_WMA', title = 'Type',                    inline = 'Slow',
  options = ['RSS_WMA', 'WMA', 'EMA', 'SMA', 'HMA'], group = grp_m)

Fil_Src    = input.source(close,    title='Filter Source',         inline = 'Filter', group = grp_f)
Fil_Length  = input.int(40,       title='Length', minval = 1, inline = 'Filter', group = grp_f)
Fil_Type    = input.string('SMA', title = 'Type',                   inline = 'Filter', group = grp_f,
  options = ['RSS_WMA', 'WMA', 'EMA', 'SMA', 'HMA'])



//==================================================================================
//f_UsePreset() =>   //function
iProxy_Src  = close, iProxy_Length  = 5 , iProxy_Type = "WMA"
iFast_Src   = close, iFast_Length   = 10, iFast_Type  = "SMA"
iSlow_Src   = close, iSlow_Length   = 20, iSlow_Type  = "SMA"
iFil_Src    = close, iFil_Length    = 50, iFil_Type   = "SMA"

if presets 
    if s_preset == pset_1
        iProxy_Src  := close, iProxy_Length := 8 , iProxy_Type  := "RSS_WMA"
        iFast_Src   := close, iFast_Length  := 15, iFast_Type   := "RSS_WMA"
        iSlow_Src   := close, iSlow_Length  := 21, iSlow_Type   := "RSS_WMA"
        iFil_Src    := close, iFil_Length   := 30, iFil_Type    := "SMA"

    else if s_preset == pset_2
        iProxy_Src  := close, iProxy_Length := 5 , iProxy_Type  := "WMA"
        iFast_Src   := close, iFast_Length  := 10, iFast_Type   := "SMA"
        iSlow_Src   := close, iSlow_Length  := 20, iSlow_Type   := "SMA"
        iFil_Src    := close, iFil_Length   := 40, iFil_Type    := "SMA"
    
    else if s_preset == pset_3
        iProxy_Src  := close, iProxy_Length := 7 , iProxy_Type  := "EMA"
        iFast_Src   := close, iFast_Length  := 21, iFast_Type   := "EMA"
        iSlow_Src   := close, iSlow_Length  := 30, iSlow_Type   := "EMA"
        iFil_Src    := close, iFil_Length   := 50, iFil_Type    := "SMA"

    else if s_preset == pset_4
        iProxy_Src  := close, iProxy_Length := 10, iProxy_Type  := "EMA"
        iFast_Src   := close, iFast_Length  := 21, iFast_Type   := "EMA"
        iSlow_Src   := close, iSlow_Length  := 50, iSlow_Type   := "SMA"
        iFil_Src    := close, iFil_Length   := 100, iFil_Type   := "SMA"

    else
        iProxy_Src  := close, iProxy_Length := 10, iProxy_Type  := "EMA"
        iFast_Src   := close, iFast_Length  := 21, iFast_Type   := "EMA"
        iSlow_Src   := close, iSlow_Length  := 100, iSlow_Type  := "SMA"
        iFil_Src    := close, iFil_Length   := 200, iFil_Type   := "SMA"

else
    iProxy_Src := Proxy_Src, iProxy_Length := Proxy_Length, iProxy_Type := Proxy_Type
    iFast_Src := Fast_Src, iFast_Length := Fast_Length, iFast_Type := Fast_Type
    iSlow_Src := Slow_Src, iSlow_Length := Slow_Length, iSlow_Type := Slow_Type
    iFil_Src := Fil_Src, iFil_Length := Fil_Length, iFil_Type := Fil_Type
// =======================================================================================// ------------------------------------------------------------------------------------------------
// Calculation
// ------------------------------------------------------------------------------------------------



LL1     = f_getMA(iProxy_Src, iProxy_Length, iProxy_Type)
LL2     = f_getMA(iFast_Src, iFast_Length, iFast_Type)
LL3     = f_getMA(iSlow_Src, iSlow_Length, iSlow_Type)
Filter  = f_getMA(iFil_Src, iFil_Length, iFil_Type)

plot(LL1, "Proxy Line", color = color.white,  display = display.none)
plot(LL2, "Fast MA",    color = color.new(#00bcd4,0), display = display.none)
plot(LL3, "Slow MA",    color = color.new(#2424f0,0), display = display.none)

Mode_Long   = LL1 > LL2 and LL2 > LL3 
Mode_Short  = LL1 < LL2 and LL2 < LL3

c_Filter    = Mode_Long ? color.new(#00bcd4,25) : Mode_Short ? color.new(#ff9800,25) : color.new(#5d606b,40)

plot(Filter, "Filter MA", linewidth = 3, color = c_Filter, style = plot.style_circles)



