Buying Selling Volume low lagOriginally written by @ceyhun
I added a low lag filter to key components to smooth the bars. The user can adjust the parameters 'fast' and 'slow' to tune.
capam
The original comments of ceyhun are below repeated:
Buying Selling Volume
-Buy Volume
-Sell Volume
-Buy Volume Percent %
-Sell Volume Percent %
-Volume Index
-Buy Sell Volume-
BuyVolume>SellVolume=Blue barcolor
SellVolume>BuyVolume=Purple barcolor
-Volume Index-
VolumeIndex>length and close > open =Cyan barcolor
VolumeIndex>length and close < open =Gray barcolor
VolumeIndex<=length = Yellow barcolor
Lowlag
Shapeshifting Moving Average - Switching From Low-Lag To SmoothThe term "shapeshifting" is more appropriate when used with something with a shape that isn't supposed to change, this is not the case of a moving average whose shape can be altered by the length setting or even by an external factor in the case of adaptive moving averages, but i'll stick with it since it describe the purpose of the proposed moving average pretty well.
In the case of moving averages based on convolution, their properties are fully described by the moving average kernel ( set of weights ), smooth moving averages tend to have a symmetrical bell shaped kernel, while low lag moving averages have negative weights. One of the few moving averages that would let the user alter the shape of its kernel is the Arnaud Legoux moving average, which convolve the input signal with a parametric gaussian function in which the center and width can be changed by the user, however this moving average is not a low-lagging one, as the weights don't include negative values.
Other moving averages where the user can change the kernel from user settings where already presented, i posted a lot of them, but they only focused on letting the user decrease or increase the lag of the moving average, and didn't included specific parameters controlling its smoothness. This is why the shapeshifting moving average is proposed, this parametric moving average will let the user switch from a smooth moving average to a low-lagging one while controlling the amount of lag of the moving average.
Settings/Kernel Interaction
Note that it could be possible to design a specific kernel function in order to provide a more efficient approach to today goal, but the original indicator was a simple low-lag moving average based on a modification of the second derivative of the arc tangent function and because i judged the indicator a bit boring i decided to include this parametric particularity.
As said the moving average "kernel", who refer to the set of weights used by the moving average, is based on a modification of the second derivative of the arc tangent function, the arc tangent function has a "S" shaped curve, "S" shaped functions are called sigmoid functions, the first derivative of a sigmoid function is bell shaped, which is extremely nice in order to design smooth moving averages, the second derivative of a sigmoid function produce a "sinusoid" like shape ( i don't have english words to describe such shape, let me know if you have an idea ) and is great to design bandpass filters.
We modify this 2nd derivative in order to have a decreasing function with negative values near the end, and we end up with:
The function is parametric, and the user can change it ( thus changing the properties of the moving average ) by using the settings, for example an higher power value would reduce the lag of the moving average while increasing overshoots. When power < 3 the moving average can act as a slow moving average in a moving average crossover system, as weights would not include negative values.
Here power = 0 and length = 50. The shapeshifting moving average can approximate a simple moving average with very low power values, as this would make the kernel approximate a rectangular function, however this is only a curiosity and not something you should do.
As A Smooth Moving Average
“So smooth, and so tranquil. It doesn't get any quieter than this”
A smooth moving average kernel should be : symmetrical, not to width and not to sharp, bell shaped curve are often appropriates, the proposed moving average kernel can be symmetrical and can return extremely smooth results. I will use the Blackman filter as comparison.
The smooth version of the moving average can be used when the "smooth" setting is selected. Here power can only be an even number, if power is odd, power will be equal to the nearest lowest even number. When power = 0, the kernel is simply a parabola:
More smoothness can be achieved by using power = 2
In red the shapeshifting moving average, in green a Blackman filter of both length = 100. Higher values of power will create lower negative values near the border of the kernel shape, this often allow to retain information about the peaks and valleys in the input signal. Power = 6 approximate the Blackman filter pretty well.
Conclusion
A moving average using a modification of the 2nd derivative of the arc tangent function as kernel has been presented, the kernel is parametric and allow the user to switch from a low-lag moving average where the lag can be increased/decreased to a really smooth moving average.
As you can see once you get familiar with a function shape, you can know what would be the characteristics of a moving average using it as kernel, this is where you start getting intimate with moving averages.
On a side note, have you noticed that the views counter in posted ideas/indicators has been removed ? This is truly a marvelous idea don't you think ?
Thanks for reading !
Right Sided Ricker Moving Average And The Gaussian DerivativesIn general gaussian related indicators are built by using the gaussian function in one way or another, for example a gaussian filter is built by using a truncated gaussian function as filter kernel (kernel refer to the set weights) and has many great properties, note that i say truncated because the gaussian function is not supposed to be finite. In general the gaussian function is represented by a symmetrical bell shaped curve, however the gaussian function is parametric, and the user might adjust the position of the peak as well as the width of the curve, an indicator using this parametric approach is the Arnaud Legoux moving average (ALMA) who posses a length parameter controlling the filter length, a peak parameter controlling the position of the peak of the gaussian function as well as a width parameter, those parameters can increase/decrease the lag and smoothness of the moving average output.
However what about the derivatives of the gaussian function ? We don't talk much about them and thats a pity because they are extremely interesting and have many great properties as well, therefore in this post i'll present a low lag moving average based on the modification of the 2nd order derivative of the gaussian function, i believe this post will be extremely informative and i hope you will enjoy reading it, if you are not a math person you can skip the introduction on gaussian derivatives and their properties used as filter kernel.
Gaussian Derivatives And The Ricker Wavelet
The notion of derivative is continuous, so we will stick with the term discrete derivative instead, which just refer to the rate of change in the function, we have a change function in pinescript, and we will be using it to show an approximation of the gaussian function derivatives.
Earlier i used the term 2nd order derivative, here the derivative order refer to the order of differentiation, that is the number of time we apply the change function. For example the 0 (zeroth) order derivative mean no differentiation, the 1st order derivative mean we use differentiation 1 time, that is change(f) , 2nd order mean we use differentiation 2 times, that is change(change(f)) , derivates based on multiple differentiation are called "higher derivative". It will be easier to show a graphic :
Here we can see a normal gaussian function in blue, its scaled 1st order derivative in orange, and its scaled 2nd derivative in green, note that i use scaled because i used multiplication in order for you to see each curve, else it would have been less easy to observe them. The number of time a gaussian function derivative cross 0 is based on the order of differentiation, that is 2nd order = the function crossing 0 two times.
Now we can explain what is the Ricker wavelet, the Ricker wavelet is just the normalized 2nd order derivative of a gaussian function with inverted sign, and unlike the gaussian function the only thing you can change is the width parameter. The formula of the Ricker wavelet is show'n here en.wikipedia.org , where sigma is the width parameter.
The Ricker wavelet has this look :
Because she is shaped like a sombrero the Ricker wavelet is also called "mexican hat wavelet", now what would happen if we used a Ricker wavelet as filter kernel ? The response is that we would end-up with a bandpass filter, in fact the derivatives of the gaussian function would all give the kernel of a bandpass filter, with higher order derivatives making the frequency response of the filter approximate a symmetrical gaussian function, if i recall a filter using the first order derivative of a gaussian function would give a frequency response that is left skewed, this skewness is removed when using higher order derivatives.
The Indicator
I didn't wanted to make a bandpass filter, as lately i'am more interested in low-lag filters, so how can we use the Ricker wavelet to make a low-lag low-pass filter ? The response is by taking the right side of the Ricker wavelet, and since values of the wavelets are negatives near the border we know that the filter passband is non-monotonic, that is we know that the filter will have low-lag as frequencies in the passband will be amplified.
So taking the right side of the Ricker wavelet only mean that t has to be greater than 0 and linearly increasing, thats easy, however the width parameter can be tricky to use, this was already the case with ALMA, so how can we work with it ? First it can be seen that values of width needs to be adjusted based on the filter length.
In red width = 14, in green width = 5. We can see that an higher values of width would give really low weights, when the number of negative weights is too important the filter can have a negative group delay thus becoming predictive, this simply mean that the overshoots/undershoots will be crazy wild and that a great fit will be impossible.
Here two moving averages using the previous described kernels, they don't fit the price well at all ! In order to fix this we can simply define width as a function of the filter length, therefore the parameter "Percentage Width" was introduced, and simply set the width of the Ricker wavelet as p percent of the filter length. Lower values of percent width reduce the lag of the moving average, but lets see precisely how this parameter influence the filter output :
Here the filter length is equal to 100, and the percent width is equal to 60, the fit is quite great, lower values of percent width will increase overshoots, in fact the filter become predictive once the percent width is equal or lower to 50.
Here the percent width is equal to 50. Higher values of percent width reduce the overshoots, and a value of 100 return a filter with no overshoots that is suited to act as a lagging moving average.
Above percent width is set to 100. In order to make use of the predictive side of the filter, it would be great to introduce a forecast option, however this require to find the best forecast horizon period based on length and width, this is no easy task.
Finally lets estimate a least squares moving average with the proposed moving average, you know me...a percent width set to 63 will return a relatively good estimate of the LSMA.
LSMA in green and the proposed moving in red with percent width = 63 and both length = 100.
Conclusion
A new low-lag moving average using a right sided Ricker wavelet as filter kernel has been introduced, we have also seen some properties of gaussian derivatives. You can see that lately i published more moving averages where the user can adjust certain properties of the filter kernel such as curve width for example, if you like those moving averages you can check the Parametric Corrective Linear Moving Averages indicator published last month :
I don't exclude working with pure forms of gaussian derivatives in the future, as i didn't published much oscillators lately.
Thx for reading !
Low Lag Exponential Moving AverageThis is a low-lag EMA, colorized to help identify turn around points. You have the option of making it adaptive as well, different methods
of signal processing or simply an average of the two.
See my previous script to understand how these adaptive methods work
Moving Average 3.0 (3rd Generation)Moving Average 3.0 (3rd Generation) script.
This indicator was originally developed and described by Dr. Manfred G. Dürschner in his paper "Gleitende Durchschnitte 3.0".
Gaussian FilterGaussian Filter script.
This indicator was described by John F. Ehlers in his book "Rocket Science for Traders" (2001, Chapter 15: Infinite Impulse Response Filters).
Ehlers Super Passband FilterEhlers Super Passband Filter script.
This indicator was originally developed by John F. Ehlers (Stocks & Commodities V. 34:8: The Super Passband Filter).
Ehlers StochasticEhlers Stochastic script.
This indicator was originally developed by John F. Ehlers (Stocks & Commodities V. 32:1: Predictive And Successful Indicators).
Ehlers Leading IndicatorEhlers Leading Indicator script.
This indicator was originally developed by John F. Ehlers (see his book `Cybernetic Analysis for Stocks and Futures`, Chapter 16: `Leading Indicators`).