Trend Regularity Adaptive Moving Average

The following moving average adapts to the average number of highest high/lowest low made over a specific period, thus adapting to trend strength. Interesting results can be obtained when using the moving average in a MA crossover system or as a trailing support/resistance .

1. Settings

Settings

  • Length : Period of the indicator, with higher values returning smoother results.
  • Src : Source input of the indicator.

2. Usage

The trend regularity adaptive moving average (TRAMA) can be used like most moving averages, with the advantage of being smoother during ranging markets.

Notice how the moving closer to the price the longer a trend last, such effect can be practical to have early entry points when using the moving average in a MA crossover system, such effect is due to the increasing number of average highest high/lowest low made during longer trends. Note that in the case of a significant uptrend followed by a downtrend, the moving average might penalize the start of the downtrend (and vice versa).

The moving average can also act as an interesting trailing support/resistance .

3. Details

The moving average is calculated using exponential averaging, using as smoothing factor the squared simple moving average of the number of highest high/lowest low previously made, highest high/lowest low are calculated using rolling maximums/minimums.

Using higher values of length will return fewer highest high/lowest low which explains why the moving average is smoother for higher length values. Squaring allows the moving average to penalize lower values, thus appearing more stationary during ranging markets, it also allows to have some consistency regarding the length setting.

4. Source Code

// This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License https://creativecommons.org/licenses/by-sa/4.0/
// © LuxAlgo
//@version=4
study("Trend Regularity Adaptive Moving Average","TRAMA",overlay=true)
length=input(100),src = input(close)
//----
ama = 0.
hh = max(sign(change(highest(length))),0)
ll = max(sign(change(lowest(length))*-1),0)
tc = pow(sma(hh or ll ? 1 : 0,length),2)
ama := nz(ama[1]+tc*(src-ama[1]),src)
plot(ama,"Plot",#ff1100,2)

Lux Algo aims to provide traders with truly useful, unique, & reliable tools that can give them an edge over others in any market.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store