RedKTrader

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

RedKTrader Uppdaterad   
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,
Versionsinformation:
typo fixed in code comments
Skript med en öppen källkod

I sann TradingView-anda har författaren publicerat detta skript med öppen källkod så att andra handlare kan förstå och verifiera det. Hatten av för författaren! Du kan använda det gratis men återanvändning av den här koden i en publikation regleras av våra ordningsregler. Du kan ange den som favorit för att använda den i ett diagram.

Frånsägelse av ansvar

Informationen och publikationerna är inte avsedda att vara, och utgör inte heller finansiella, investerings-, handels- eller andra typer av råd eller rekommendationer som tillhandahålls eller stöds av TradingView. Läs mer i Användarvillkoren.

Vill du använda det här skriptet i ett diagram?