Cumulative Weighted Triple Exponential Moving Average (CWTEMA)
// 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("CWTEMA", overlay = true)

// Define the triple exponential moving average function
tema(src, len) =>
    // Compute the weights for each value in the moving average
    weights = (len + 1) / 2 - math.abs(len - src)
    // Calculate the triple exponential moving average
    tema = 3 * ta.ema(src, len) - 3 * ta.ema(ta.ema(src, len), len) + ta.ema(ta.ema(ta.ema(src, len), len), len)

// Define the weighted moving average function
wma(src, weights, int len) =>
    // Compute the weighted sum of the source data
    weightedSum = math.sum(src * weights, len)
    // Compute the sum of the weights
    sumWeights = math.sum(weights, len)
    // Divide the weighted sum by the sum of the weights to calculate the weighted average
    weightedSum / sumWeights

cweema(src, len) =>
    // Compute the weights for each value in the moving average
    weights = (len + 1) / 2 - math.abs(len - src)
    // Calculate the weighted moving average
    wma(tema(src, len), weights, len)


source = input.source(close, 'Source')
length = input.int(100, "Length", 1)
plot(cweema(source, length))
