RedKTrader

TA Basics: Creating a Zero Lag Moving Average using "Mirroring"

RedKTrader 已更新   
we all know how moving averages suffer from lag - they have a delayed response to change in the underlying values - regardless if the underlying values are price movement or some kind of indicator formula that we are trying to smooth using a moving average.

here's a simple technique that can help minimize the lag built into the moving average - you can use this technique while building your own indicator (say modifying RSI) or simply apply it to a price chart to generate some sort of signal.

the concept here is simple and it actually depends on the fact that there's lag in moving averages - however, it was also observed that this lag is less when we use a weighted moving average (WMA) vs a simple moving average (SMA). (for a quick intro / refresher on Moving Averages, there's an awesome write-up here on TradingView that you can easily find with a quick search)

so the idea is to take the delta between these 2 lines (which is mathematically equal to SMA - WMA) , and "mirror it" on the other side of the WMA to produce the new Zero-lag line (let's call it ZLMA. sounds easy, right?

now, expanding on this concept just one step further, while we're at it, why don't we take, say, 1.5 times that delta, or 2 times and mirror it - wouldn't that produce an even less lagging line that moves in lockstep with the price (or whatever data series)? -- yes it would, we added that in the sample code here, but be careful with that, if you increase that factor too much, the ZLMA starts behaving "wildly" and loses relevance to the underlying data. so keep it from 1 to 2.5 -- an ideal value would be around the 1.5 (and of course, for the mathematically gifted, as you expect, you make that factor -1.0, and you end up with a ZLMA that is exactly same as the SMA :) ..

if you don't use a ZLMA factor "f" -- then the simple equation is ZLMA = 2W - S, which you can simply add to any indicator to smoother it without introducing a lot of lag -- however, i still suggest you keep that smoothing to a small value between 3 and 6 -- to stay relevant to underlying data


hope you like this and find it useful. let me know -- i'd like to know if there's interest in these types of concepts and there's more to come.

pls stay safe,
版本注释:
typo fixed in code comments
开源脚本

本着真正的TradingView精神,该脚本的作者将其开源发布,以便交易者可以理解和验证它。为作者喝彩!您可以免费使用它,但在出版物中重复使用此代码受网站规则的约束。 您可以收藏它以在图表上使用。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?