Skip to main content

TMA

Source

https://github.com/quadcode-tech/quadcodescript-library/blob/master/averages/ma_tma.lua

Syntax Format

tma(series, period)

Overview

TMA (Triangular Moving Average) is aimed to smooth the price movement and show more significant trends. The main difference of this Moving Average is adding an extra averaging layer for extra smoothing of the price movement. The TMA is suitable for long-term strategies, reducing the noise and showing prominent trends.

Parameters

ParameterTypePurpose
sourceseriesInput series, taken into calculation
periodnumericMoving Average period

Returns*: series.

*If there are less than 2period-1 values in the series – the result is nan.

Example

instrument { name = "Triangular Moving Average", short_name = "TMA", overlay = true, icon="indicators:MA" }

period = input (10, "period", input.integer, 1)
source = input (1, "source", input.string_selection, inputs.titles_overlay)

input_group {
"TMA Line",
color = input { default = "#4BFFB5", type = input.color },
width = input { default = 1, type = input.line_width}
}

local sourceSeries = inputs [source]

plot (tma (sourceSeries, period), "TMA", color, width)

Formula

The formula for calculating TMA is:

image.png

The first value of TMA is calculated as sma(series, period). Then, in order to add an extra averaging layer, another SMA is added.