Moving Average Converging

Category: Indicators By: LucasBest Created: August 29, 2023, 2:04 PM
August 29, 2023, 2:04 PM
Indicators
0 Comments

This indicator returns a moving average converging toward the price the more a trend makes new higher-highs or lower-lows depending on the detected trend.

Settings

  • Length: Controls the initial moving average smoothing factor (2 / (Length + 1)), as well as the period of rolling maximums/minimums.
  • Increment: Smoothing factor increment (2 / (Increment+ 1)) for new higher-high/lower-low, lower values would return a faster converging moving average.
  • Fast: Fast moving average smoothing factor.

Usage

The proposed moving average can be used like most slow moving averages.

Having a moving average able to converge closer to the price the longer a trend lasts allows users to obtain more timely crosses.

// by LuxAlgo

length=100
incr=10
fast=10
If barindex > length then
//Settings
src = customclose

//Calculations
once ma = 0
once fma = 0
once alpha = 0
once k = 1/incr

upper = highest[length]
lower = lowest[length]

initma = average[length](src)

cross = src crosses under ma or src crosses over ma

If cross then
alpha = 2 /(length+1)
elsif (src > ma and upper > upper[1]) or (src < ma and lower < lower[1]) then
alpha = alpha + k
endif

ma = ma[1] + alpha[1]*(src - ma[1])
If ma = 0 then
ma = initma
endif

If cross then
fma = (src+fma[1])/2
elsif src > ma then
fma = MAX(src,fma[1])+((src-fma[1])/fast)
else
fma = MIN(src,fma[1])+((src-fma[1])/fast)
Endif

If fma = 0 then
fma = src
endif

If fma > ma then
r = 10
g = 255
b = 10
else
r = 255
g = 10
b = 10
Endif

Colorbetween(fma,ma,r,g,b,30)

Endif

Return fma coloured("red",100), ma style(line,3)coloured (r,g,b,255)

Download
Filename: Moving-Average-Converging.itf
Downloads: 103
LucasBest Junior
As an architect of digital worlds, my own description remains a mystery. Think of me as an undeclared variable, existing somewhere in the code.
Author’s Profile

Comments

Logo Logo
Loading...