Triple Exponential Hull Moving Average THMA
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © peacefulLizard50262

//@version=5
indicator("THMA", overlay =  true)
gaussianma(values, length) =>
    // Define the standard deviation of the Gaussian distribution
    stddev = length / 4
    // Generate an array of indices from 1 to length
    indices = ta.range(1, length)
    // Calculate the Gaussian weights for each value in the array
    weights = math.exp(-0.5 * (math.pow((indices - length), 2) / math.pow(stddev, 2)))
    // Calculate the weighted sum of the values
    sum = math.sum(values * weights, length)
    // Return the moving average
    sum / math.sum(weights, length)
ema(src, len, a) => //{
    alpha = a / (len + 1)
    sum   = 0.0
    sum  := na(sum[1]) ? src : alpha * src + (1 - alpha) * nz(sum[1])

thma(src, len, a, smoothing) =>
    gaussianma(ema(ema(ema(src, int(len/2), a), int(math.sqrt(len/2)), a), int(math.sqrt(len/2)), a), smoothing)

Source = input.source(close)
Length = input.int(200, minval = 2)
alpha  = input.float(10, "Alpha", 0.01, step = 0.5)
smoothing = input.int(1, "Smoothing", 1)
thma = thma(Source, Length, alpha, smoothing)
hma_dif = (thma - thma[2])/2
colour = math.sign(hma_dif) == 1 ? color.green : color.red
plot(thma, "EHMA", colour)

