- length : Number of inputs to be used.
- src : Source input of the indicator.
- mult : Multiplication factor for the RMSE, determine the distance between the upper and lower level.
In a can provide an estimate of the underlying trend in the price, this result can be extrapolated to have an estimate of the future evolution of the trend, while the upper and lower level can be used as levels.
The slope of the fitted line indicates both the direction and strength of the trend, with a positive slope indicating an up-trending market while a negative slope indicates a down-trending market, a steeper line indicates a stronger trend.
We can see that the trend of the S&P500 in this chart is approximately linear, the upper and lower levels were previously tested and might return accurate points in the future.
By using a we are making the following assumptions:
- The trend is linear or approximately linear.
- The cycle component has an approximately constant amplitude (this allows the upper and lower level to be more effective)
- The underlying trend will have the same evolution in the future
In the case where the growth of a trend is non-linear, we can use a logarithmic scale to have a linear representation of the trend.
In a simple , we want to the slope and intercept parameters that minimize the sum of squared residuals between the data points and the fitted line
intercept + x*slope
Both the intercept and slope have a simple solution, you can find both in the calculations of the , in fact, the last point of the with period length is equal to the last point of a fitted through the same length data points. We have seen many times that the is an FIR filter with a series of coefficients representing a linearly decaying function with the last coefficients having a negative value, as such we can calculate the more easily by using a linear combination between a and SMA: 3WMA - 2SMA, this linear combination gives us the last point of our , denoted point B.
Now we need the first point of our , by using the calculations of the we get this point by using:
intercept + (x-length+1)*slope
If we get the impulse response of such we get
In blue the impulse response of a standard , in red the impulse response of the using the previous calculation, we can see that both are the same with the exception that the red one appears as being time inverted, the first coefficients are negative values and as such we also have a linear operation involving the and but with inverted terms and different coefficients, therefore the first point of our , denoted point A, is given by 4SMA - 3WMA, we then only need to join these two points thanks to "line.new".
The levels are simply equal to the fitted line plus/minus the root mean squared error between the fitted line and the data points, right now we only have two points, we need to find all the points of the fitted line, as such we first need to find the slope, which can be calculated by diving the vertical distance between B and A (the rise) with the horizontal distance between B and A (the run), that is
(A - B)/(length-1)
Once done we can find each point of our line by using
B + slope*i
where i is the position of the point starting from B, i=0 give B since B + slope*0 = B, then we continue for every i, we then only need to sum the squared distance between each closing prices at position i and the point found at that same position, we divide by length-1 and take the square root of the result in order to have the RMSE.
The following post as shown that it was possible to compute a by using a linear combination between the and , since both had extremely efficient computations (see link at the end of the post) we could have a calculation for the where the number of operations is independent of length.
This post took me eons to make because it's related to the , and I am rarely short on words when it comes to anything related to the . Thx to LucF for the feedback and everything.
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 автор этого скрипта опубликовал его с открытым исходным кодом, чтобы трейдеры могли понять, как он работает, и проверить на практике. Вы можете воспользоваться им бесплатно, но повторное использование этого кода в публикации регулируется Правилами поведения. Вы можете добавить этот скрипт в избранное и использовать его на графике.