Nonlinear Regression, Zero-lag Moving Average [Loxx]Nonlinear Regression and Zero-lag Moving Average
Technical indicators are widely used in financial markets to analyze price data and make informed trading decisions. This indicator presents an implementation of two popular indicators: Nonlinear Regression and Zero-lag Moving Average (ZLMA). Let's explore the functioning of these indicators and discuss their significance in technical analysis.
Nonlinear Regression
The Nonlinear Regression indicator aims to fit a nonlinear curve to a given set of data points. It calculates the best-fit curve by minimizing the sum of squared errors between the actual data points and the predicted values on the curve. The curve is determined by solving a system of equations derived from the data points.
We define a function "nonLinearRegression" that takes two parameters: "src" (the input data series) and "per" (the period over which the regression is calculated). It calculates the coefficients of the nonlinear curve using the least squares method and returns the predicted value for the current period. The nonlinear regression curve provides insights into the overall trend and potential reversals in the price data.
Zero-lag Moving Average (ZLMA)
Moving averages are widely used to smoothen price data and identify trend directions. However, traditional moving averages introduce a lag due to the inclusion of past data. The Zero-lag Moving Average (ZLMA) overcomes this lag by dynamically adjusting the weights of past values, resulting in a more responsive moving average.
We create a function named "zlma" that calculates the ZLMA. It takes two parameters: "src" (the input data series) and "per" (the period over which the ZLMA is calculated). The ZLMA is computed by first calculating a weighted moving average (LWMA) using a linearly decreasing weight scheme. The LWMA is then used to calculate the ZLMA by applying the same weight scheme again. The ZLMA provides a smoother representation of the price data while reducing lag.
Combining Nonlinear Regression and ZLMA
The ZLMA is applied to the input data series using the function "zlma(src, zlmaper)". The ZLMA values are then passed as input to the "nonLinearRegression" function, along with the specified period for nonlinear regression. The output of the nonlinear regression is stored in the variable "out".
To enhance the visual representation of the indicator, colors are assigned based on the relationship between the nonlinear regression value and a signal value (sig) calculated from the previous period's nonlinear regression value. If the current "out" value is greater than the previous "sig" value, the color is set to green; otherwise, it is set to red.
The indicator also includes optional features such as coloring the bars based on the indicator's values and displaying signals for potential long and short positions. The signals are generated based on the crossover and crossunder of the "out" and "sig" values.
Wrapping Up
This indicator combines two important concepts: Nonlinear Regression and Zero-lag Moving Average indicators, which are valuable tools for technical analysis in financial markets. These indicators help traders identify trends, potential reversals, and generate trading signals. By combining the nonlinear regression curve with the zero-lag moving average, this indicator provides a comprehensive view of the price dynamics. Traders can customize the indicator's settings and use it in conjunction with other analysis techniques to make well-informed trading decisions.
Zlma
RedK DIY ZLMA: Customizable Zero-Lag MA (Educational / Utility)This script is more of an educational / utility piece rather than a fully-fledged indicator - It provides an easy way to customize and produce a zero-lag Moving average that can then be used in various scenarios
What is DIY_ZLMA?
------------------------
The DIY ZLMA is for fans and enthusiasts of researching Moving Averages (like me) - the script enables the user to play around with one of the common approaches used to reduce lag in moving averages - which was explained in this old post below
Suggested uses of the DIY_ZLMA
---------------------------------------
* The Zero-lag approach here applies 3 moving average passes to a source data series - I'll refer to these 3 passes as Base MA Pass , De-lagging Pass, and Smoothing Pass - these "passes" can be customized from the indicator settings in terms of MA Length and type. The first pass allows the choice of a "source", and the second pass allows additional fine tuning by playing around with the magnification factor. The 3rd pass (smoothing) is optional and can be skipped altogether when needed. (as noted in the script, HMA and TEMA, which are very common low-lag MA's use slightly different approach in the calculation than the one used here .. so we can't get an equivalent of either of these MA's with the customization of DIY_ZLMA parameters)
* After the user experiments with the various settings for the 3 passes, and finds a "preferred combination", the script not only plots the resulting My_ZLMA - it also produces the "1-line Pine script formula" that the user can then use in any other script, maybe to smoothen some data series, or to combine with other types of moving averages to create multi-MA cross-over trading signals... and so on.
* The DIY_ZLMA can also be added to another indicator as a signal line using the Indicator-on-Indicator feature of TradingView (review this post for step-by-step -->
)
* the script also showcases couple of recent (and very neat) Pine features: the use of User-defined Types (UDT) and User-defined Methods - which are awesome and a lot of fun to work with :)
Since this is more of a utility piece, I added as many comments as possible to the script to explain the way it works - so it's more valuable if someone finds it by searching the "Add Indicator" feature in TradingView charts
Please feel free to play around with this new toy :) and share comments and feedback below if you find this useful. I truly hope you do.
Zero Lag Detrended Price Oscillator (ZL DPO)This indicator attempts to create a zero lag Detrended price oscillator using 2 different scripts. I actually really like the results so far. I hope you all find it useful too.
Green>Red = long
Red>Green = short
The lines on the example chart are some of the signals that the indicator gave on default settings.
The greens are wins, reds are outright losses, and blues are "scratch" trades(signal for other side before hitting stop loss).
All of the signals tested were using NNFX money management to see if they are wins or losses(1.5x atr for SL and 1 Atr for TP).
RedK Dual-Color Zero-Lag Moving Average (RedK ZLMA v1)Here's my Dual-color Zero-Lag Moving Average indicator - with alerts - as a separate study
This is published in response to couple of requests i received. Please refer to previous posts on TA Basics on creating zero-lag MAs for more background.
This version adds couple of extras
---------------------------------------------
- the ability to choose the price being used (close vs hl2, hlc3..etc)
- ability to change resolution
the example chart below on the right uses a weekly resolution for the ZLMA on top of a daily chart - the left chart shows the same view but with the ZLMA resolution set to "same as chart"
- Alerts-enabled for when trend change is detected
- optional smoothing - keep the smoothing low (3 or 4) else it introduces lagging again
i hope some will find this useful
- the code is light and can easily be integrated into other indicators of your own - or you can add this ZLMA to your charts in combination with other MA's you use to easily identify trends and swings.
let me know your feedback.
Good luck!
TA Basics: Evolving our Zero Lag Moving Average.In the previous Zero-Lag MA post, we introduced the "mirroring" technique and the associated calculation.
In this post, we will see how we can use the same technique, with a slight variation, to evolve our zero lag moving average line, add more "smoothness" and still maintaining the low lag and fast response to data series changes.
to use the "mirroring" technique, we need to use 2 MA lines with varying speeds - this is essential to produce the delta between the lines, that can then be mirrored around the fast line to produce the final line. in the first example, we used a Simple MA (slow) and a Weighted MA (fast) of the same length to achieve that.
here we introduce a different way of doing that. we will use a Weighted MA of the length (slow) and another Weighted MA of half the length (fast) -- the difference in "speed" between these 2 lines should produce the delta we need, we mirror it around the fast line, and we get our desired Zero-lag line. Check!
then while we're at it, why don't we introduce an additional smoothing just to ensure the new line is not too "broken" and jumpy .. and flows smoothly across the data series. but what length should we use for smoothing?
smoothing length should be enough to make an actual smoothing effect, but not too large else it will introduce lagging on its own. how about 3? usually 3 or 4 are good values for smoothing. A brilliant idea here is to use a number related to the same input length of the original line, which can always be relatively small -- the square root (integer portion) of that original length - and in that case, the user will only need to enter 1 input for the moving average, just the length - everything will be calculated from there. Check again!
I commented the code if you like to follow the simplified build-up of the formula, now that the concept is explained.
the (more complex-looking) 1-line, condensed form of that formula to use is (alert: watch out for the ()'s -- they're tricky :) )
----------------------------------------------
ZLMA_Line = wma((2*wma(close,int(length/2)) - wma(close,length)), int(sqrt(length)))
------------------------------------------
the one thing i do not like about this technique, is that we introduce the use of the half length MA. i do not like to build indicators that make decisions like this on behalf of the trader - the trader wants to analyze the data for a specific length, and we should continue to stick to that consistently across the moving average (or whatever indicator) calculation. I would always be caution about "hardcoding" some optional values (in this case 0.5 * length) within the indicator itself - others may not mind that.
Now to a nice surprise for the patient folks who got so far in this post - Congratulations, we have just discovered the concept and the formula behind the famous Hull Moving Average .. the big thing here is, we just had the opportunity to learn how to create the whole thing ourselves from the ground up step by step, and had fun doing it (I hope!)
-- these posts are meant to provide those who are new to the world of technical analysis and want to learn how and why to build their own technical indicators. i hope some of you find them useful and interesting, and i wish you the best of luck.
Zero Lag Keltner ChannelsThis is Keltner Channelz (KC) with Zero Lag Moving Average (ZLMA as base). It is smoother and has less lag than the original (EMA/SMA) variant.
It also can be used as a trend indicator and trend confirmation indicator. The upper and lower bands are green if it is an up trend, and red if a down trend. If both have the same color it is a stronger trend.