Heikenashi higher timeframe indicator

This indicator draws a combined moving average. Select the preferred moving average type in the settings, then set the length of the moving average. This indicator can be quite useful on different symbols as confirmation of your entry strategy. The most of the supported moving averages are native Pine Scriptâ„¢ functions.

Supported moving averages

// @version=5
indicator("Combined moving average indicator", overlay=true)


// define the combined ma parameters
maType = input.string(title="Type", options=["SMA", "EMA", "WMA", "HMA", "RMA", "REMA", "SWMA", "ALMA", "VWMA", "VWAP"], defval="HMA", tooltip="Select prefered type of the combined moving average.")
maLength = input.int(title="Length", minval=0, defval=9, tooltip="Selected combined moving average length.")


// *******************************************************************************************
// Indicator helper functions
// *******************************************************************************************
rema(series float source, simple int length, float lambda) =>
    alpha = 2 / (length + 1)

    rema = 0.0
    rema := (nz(rema[1]) + alpha * (source - nz(rema[1])) + lambda * (2 * nz(rema[1]) - nz(rema[2]))) / (lambda + 1)

multima(series float source, string maType, simple int maLength) =>
    // select the target moving average based on the function arguments
    switch str.upper(maType)
        "SMA"  => ta.sma(source, maLength)
        "EMA"  => ta.ema(source, maLength)
        "WMA"  => ta.wma(source, maLength)
        "HMA"  => ta.hma(source, maLength)
        "RMA"  => ta.rma(source, maLength)
        "REMA"  => rema(source, maLength, 0.5)
        "SWMA" => ta.swma(source)
        "ALMA" => ta.alma(source, maLength, 0.85, 6)
        "VWMA" => ta.vwma(source, maLength)
        "VWAP" => ta.vwap(source)
        // in case there is no moving average with the selected type
        // throw the error into the pinescript compiler console
        => runtime.error("Moving average type '" + maType + "' not found!"), na


// *******************************************************************************************
// Indicator rendering logic
// *******************************************************************************************
// just call the function with the selected moving average type
maData = multima(close, maType, maLength)

// render the selected moving average line
plot(maData, title="Data", style=plot.style_line, linewidth=1, color=color.blue)

Made on
Tilda