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

//@version=5

// @description moving_average: moving average variants
library("moving_average", overlay=true)

// @function variant: moving average variants
// @param string type: type in ["SMA", "EMA", "DEMA", "TEMA", "WMA", "VWMA", "SMMA", "HullMA", "TMA", "SSMA"]
// @param series float src: the source series of moving average
// @param simple int len: the length of moving average
// @returns float: the moving average variant value
export variant(string type, series float src, simple int len) =>
	//TODO : add function body and return value here
    float v1 = ta.sma(src, len)                                                  // Simple
    float v2 = ta.ema(src, len)                                                  // Exponential2
    float v3 = 2 * v2 - ta.ema(v2, len)                                          // Double Exponential
    float v4 = 3 * (v2 - ta.ema(v2, len)) + ta.ema(ta.ema(v2, len), len)         // Triple Exponential
    float v5 = ta.wma(src, len)                                                  // Weighted
    float v6 = ta.vwma(src, len)                                                 // Volume Weighted
    float v7 = 0.0
    v7 := na(v7[1]) ? v1 : (v7[1] * (len - 1) + src) / len                       // Smoothed
    float v8 = ta.wma(2 * ta.wma(src, len / 2) - ta.wma(src, len), math.round(math.sqrt(len)))   // Hull
    float v9 = ta.sma(v1,len)                                                    // Triangular (extreme smooth)
    // SuperSmoother filter
    // © 2013  John F. Ehlers
    float a1 = math.exp(-1.414*3.14159 / len)
    float b1 = 2*a1*math.cos(1.414*3.14159 / len)
    float c2 = b1
    float c3 = (-a1)*a1
    float c1 = 1 - c2 - c3
    float v10 = 0.0
    v10 := c1*(src + nz(src[1])) / 2 + c2*nz(v10[1]) + c3*nz(v10[2])
    type=="EMA"? v2: type=="DEMA"? v3: type=="TEMA"? v4: type=="WMA"? v5: type=="VWMA"? v6: type=="SMMA"? v7: type=="HullMA"?v8 : type=="TMA"? v9: type=="SSMA"? v10: v1
    
plot(variant("HullMA", close, 30))