At the start of 2019 i published my first post "Approximating A Least Square Moving Average In Pine", who aimed to provide alternatives calculation of the ( ), a moving average who aim to estimate the underlying trend in the price without excessive lag.
The has the form of a ax + b where x is a linear sequence 1.2.3..N and with time varying a and b, the exact formula of the is as follows :
a = stdev(close,length)/stdev(bar_index,length) * correlation(close,bar_index,length)
b = (close,length) - a*sma(bar_index,length)
= a*bar_index + b
Such calculation allow to forecast future values however such forecast is rarely accurate and the is mostly used as a smoother. In this post an alternative calculation is proposed, such calculation is incredibly simple and allow for an extremely efficient computation of the .
The is a FIR low-pass filter with the following impulse response :
The impulse response of a FIR filter gives us the weight of the filter, as we can see the weights of the are a linearly decreasing sequence of values, however unlike the linearly ( ) the weights of the take on negative values, this is necessary in order to provide a better fit to the data. Based on such impulse response we know that the can help calculate the , since both have weights representing a linearly decreasing sequence of values, however the doesn't have negative weights, so the process here is to fit the impulse response to the impulse response of the .
Based on such negative values we know that we must subtract the impulse response of the by a constant value and multiply the result, such constant value can be given by the impulse response of a , we must now make sure that the impulse response of the and cross at a precise point, the point where the impulse response of the is equal to 0.
We can see that 3WMA and 2SMA are equal at a certain point, and that the impulse response of the is equal to 0 at that point, if we proceed to subtraction we obtain :
LSMA = 3WMA - 2SMA = + 2( - )
On a graph the difference isn't visible, subtracting the proposed calculation with a regular of the same period gives :
the error is 0.0000000...and certainly go on even further, therefore we can assume that the error is due to rounding errors.
This post provided a different calculation of the , it is shown that the can be made from the linear combination of a and a : 3WMA + -2SMA. I encourage peoples to use impulse responses in order to estimate other moving averages, since some are extremely heavy to compute.
Thanks for reading !
Become a Patreon and get access to exclusive technical indicators!
You can also check out some of the indicators I made for luxalgo : https://www.tradingview.com/u/LuxAlgo/#published-scripts
ברוח TradingView אמיתית, מחבר הסקריפט הזה פרסם אותו בקוד פתוח, כך שסוחרים יכולים להבין ולאמת אותו. כל הכבוד למחבר! אתה יכול להשתמש בו בחינם, אך שימוש חוזר בקוד זה בפרסום כפוף לכללי הבית. אתה יכול להכניס אותו למועדפים כדי להשתמש בו בגרף.
המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.