OPEN-SOURCE SCRIPT

Shapeshifting Moving Average - Switching From Low-Lag To Smooth

The term "shapeshifting" is more appropriate when used with something with a shape that isn't supposed to change, this is not the case of a moving average whose shape can be altered by the length setting or even by an external factor in the case of adaptive moving averages, but i'll stick with it since it describe the purpose of the proposed moving average pretty well.

In the case of moving averages based on convolution, their properties are fully described by the moving average kernel (set of weights), smooth moving averages tend to have a symmetrical bell shaped kernel, while low lag moving averages have negative weights. One of the few moving averages that would let the user alter the shape of its kernel is the Arnaud Legoux moving average, which convolve the input signal with a parametric gaussian function in which the center and width can be changed by the user, however this moving average is not a low-lagging one, as the weights don't include negative values.

Other moving averages where the user can change the kernel from user settings where already presented, i posted a lot of them, but they only focused on letting the user decrease or increase the lag of the moving average, and didn't included specific parameters controlling its smoothness. This is why the shapeshifting moving average is proposed, this parametric moving average will let the user switch from a smooth moving average to a low-lagging one while controlling the amount of lag of the moving average.

Settings/Kernel Interaction

Note that it could be possible to design a specific kernel function in order to provide a more efficient approach to today goal, but the original indicator was a simple low-lag moving average based on a modification of the second derivative of the arc tangent function and because i judged the indicator a bit boring i decided to include this parametric particularity.

As said the moving average "kernel", who refer to the set of weights used by the moving average, is based on a modification of the second derivative of the arc tangent function, the arc tangent function has a "S" shaped curve, "S" shaped functions are called sigmoid functions, the first derivative of a sigmoid function is bell shaped, which is extremely nice in order to design smooth moving averages, the second derivative of a sigmoid function produce a "sinusoid" like shape (i don't have english words to describe such shape, let me know if you have an idea) and is great to design bandpass filters.

We modify this 2nd derivative in order to have a decreasing function with negative values near the end, and we end up with:

스냅샷

The function is parametric, and the user can change it (thus changing the properties of the moving average) by using the settings, for example an higher power value would reduce the lag of the moving average while increasing overshoots. When power < 3 the moving average can act as a slow moving average in a moving average crossover system, as weights would not include negative values.

스냅샷

Here power = 0 and length = 50. The shapeshifting moving average can approximate a simple moving average with very low power values, as this would make the kernel approximate a rectangular function, however this is only a curiosity and not something you should do.

As A Smooth Moving Average

“So smooth, and so tranquil. It doesn't get any quieter than this”

A smooth moving average kernel should be : symmetrical, not to width and not to sharp, bell shaped curve are often appropriates, the proposed moving average kernel can be symmetrical and can return extremely smooth results. I will use the Blackman filter as comparison.

The smooth version of the moving average can be used when the "smooth" setting is selected. Here power can only be an even number, if power is odd, power will be equal to the nearest lowest even number. When power = 0, the kernel is simply a parabola:

스냅샷

More smoothness can be achieved by using power = 2

스냅샷

In red the shapeshifting moving average, in green a Blackman filter of both length = 100. Higher values of power will create lower negative values near the border of the kernel shape, this often allow to retain information about the peaks and valleys in the input signal. Power = 6 approximate the Blackman filter pretty well.

스냅샷

Conclusion

A moving average using a modification of the 2nd derivative of the arc tangent function as kernel has been presented, the kernel is parametric and allow the user to switch from a low-lag moving average where the lag can be increased/decreased to a really smooth moving average.

As you can see once you get familiar with a function shape, you can know what would be the characteristics of a moving average using it as kernel, this is where you start getting intimate with moving averages.

On a side note, have you noticed that the views counter in posted ideas/indicators has been removed ? This is truly a marvelous idea don't you think ?

Thanks for reading !




lowlagMoving AveragessmoothTrend Analysistrigonometriczerolag

오픈 소스 스크립트

진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

차트에 이 스크립트를 사용하시겠습니까?


Check out the indicators we are making at luxalgo: tradingview.com/u/LuxAlgo/
또한 다음에서도:

면책사항