Ehlers Adaptive Relative Strength Index V1 [CC]The Adaptive Relative Strength Index was created by John Ehlers and this is his first version. I will of course publish his updated version at a later date along with publishing the final script from Jim Sloman's Ocean Theory book. I have changed his script to include extra smoothing to provide clear buy and sell signals. This is a version of a RSI that is very adaptive to changes by finding the length of the current cycle and using that to calculate the rsi and I use this same basic process to provide extra smoothing. A great strategy of course is to buy right after the indicator goes from below the oversold level to right above it and stay in until the indicator turns red or when it reaches the overbought level. I have included strong buy and sell signals in addition to normal ones and the darker colors mean strong signals and lighter colors are normal signals.
Let me know what other indicators you would like to see me publish!
Smooth
Heikin Ashi Candle OverlayHello Friend,
This is a very simple script for fun to demonstrate the new ability to change the colors of attributes pertaining to the plotbar() and plotcandle() functions using series inputs.
For Heiken Ashi lovers, this script does several things. It gives you both bars and hollow candles with Heikin Ashi values - something TV does not currently support.
It also gives you the ability to see your favorite HA candles while on the main series plot. When viewing indicators in the "Heikin Ashi" candle setting on TradingView, the input values are "smoothed' with HA values. This skews the way your indicators behave as the OLHC are calculated averages. Only the regular candle settings will give your indicators "real close" etc.
By 'Muting' the main series bars by toggling the 👁 symbol next to your ticker id, it makes the normal candles invisible. You then overlay this script, which allows you to see the HA Candle of your choice, while not affecting the way your indicators behave.
You now have the best of 2 worlds. Smoothed behavior of price action to help visualize trends, and accurate indicator values derived from actual OLHC data.
Plus, something about hollow HA candles is just kind of clean and soothing isn't it?
Cheers,
Bjorgum
Hollow Setting:
Bars
Or just plain old regular, but on the main chart
Ehlers Smoothed Adaptive Momentum [CC]The Smoothed Adaptive Momentum indicator was created by John Ehlers and this indicator gives a lot of useful information. When the indicator is above 0 then there is very strong upward momentum and when the indicator falls below 0 then there is very strong downward momentum. A very profitable way to use this particular indicator is buy long when the indicator is below 0 and it crosses over it's signal line and then sell of course when you get the first sell signal. I have included strong buy and sell signals in addition to normal ones so darker colors mean strong signals and lighter colors are normal signals. Buy when the line turns green and sell when it turns red.
Let me know if you have any other scripts you would like to see me publish!
RedK Slow_Smooth Average (RSS_WMA)RedK Slow Smooth Average (RSS_WMA) is based on simple, multi-WMA passes to generate a moving average that sacrifices low-lag and fast responsiveness for the sake of smoothness.
This smoothness enables an increased trader ability to visualize and track longer-term trends and removes the noise of smaller, relatively insignificant price fluctuations.
Notes:
=========
* RSS_WMA is deliberately built to be a "lazy line" - and it works in a different way to other common moving averages that attempt to achieve less lag and quicker responsiveness - the idea and the use scenario is to act as a "smooth base" when used against a faster moving average like the v_Wave of the Co_Ra Wave
* Note that the settings of this line is "Smoothness' and not "length" - the initial length used for the first WMA pass calculation is 1/3 of that smoothness value selected in the settings
* Increments in the combined smoothness value will be allocated first to 1st WMA pass, then 2nd WMA pass, then 3rd pass consecutively then back to 1st pass.
* because we utilize 3 WMA passes, a settings below 3 will have no effect on the line and it will just track the "source" price.
Suggested Use:
===============
- Use RSS_WMA when you're looking for a smooth moving average that can help you analyze you chart at a broader / macro level, visualize the broader price action patterns and filter out the noise from short-term moves. you can also use this line to help set your position exits since only major and persistent moves will cause this line, as lay as it is, to swing from one direction to the other.
How does RSS_WMA compare?
============================
here's a quick view of how the RSS_WMA compared to other commonly used Moving Averages, including my recently published CoRa_Wave
Code is commented - please feel free to use and customize further - please share a comment if you found this useful in your chart analysis or trading.
Trigonometric On Balance Volume (OBV) OscillatorLove volume analysis but it's hard for you to implement a simple strategy by it?
Use OBV.
Is OBV still not quite as it should be for you to get it in your trading system?
Use OBV Oscillator.
Does OBV Oscillator give you too many false signals and when you smooth it, it lags by a ton?
Then this indicator is the answer to your problem.
Introducing the Trigonometric OBV Oscillator.
The Trigonometric OBV Oscillator or "Trig OBV" for short, uses an old, but uniquely extremely reliable mathematical formula to smooth the OBV, while eliminating more than 95% of its false signals (noises) and keeping with the real direction of the trend without introducing any lags.
It is very responsive, predictive even to some degree, very reliable, and keeps you out of false trades (like false breakouts, sudden changes in the price, etc).
To go long: wait until the white line crosses up the purple line and continues in that direction.
To go short: wait until the white line crosses down the blue line and continues in that direction.
To exit, do the opposite.
Better to be used with a baseline filter such as Kaufman's moving average.
Use it and let me know what you think about it.
Trend Regularity Adaptive Moving Average [LuxAlgo]The following moving average adapt to the average number of highest high/lowest low made over a specific period, thus adapting to trend strength. Interesting results can be obtained when using the moving average in a MA crossover system or as a trailing support/resistance.
Settings
Length : Period of the indicator, with higher values returning smoother results.
Src : Source input of the indicator.
Usage
The trend regularity adaptive moving average (TRAMA) can be used like most moving averages, with the advantage of being smoother during ranging markets.
Notice how the moving closer to the price the longer a trend last, such effect can be practical to have early entry points when using the moving average in a MA crossover system, such effect is due to the increasing number of average highest high/lowest low made during longer trends. Note that in the case of a significant uptrend followed by a downtrend, the moving average might penalize the start of the downtrend (and vice versa).
The moving average can also act as an interesting trailing support/resistance.
Details
The moving average is calculated using exponential averaging, using as smoothing factor the squared simple moving average of the number of highest high/lowest low previously made, highest high/lowest low are calculated using rolling maximums/minimums.
Using higher values of length will return fewer highest high/lowest low which explains why the moving average is smoother for higher length values. Squaring allows the moving average to penalize lower values, thus appearing more stationary during ranging markets, it also allows to have some consistency regarding the length setting.
🧙 this moving average would not be possible without the existence of corn syrup 🦎
A Useful MA Weighting Function For Controlling Lag & SmoothnessSo far the most widely used moving average with an adjustable weighting function is the Arnaud Legoux moving average (ALMA), who uses a Gaussian function as weighting function. Adjustable weighting functions are useful since they allow us to control characteristics of the moving average such as lag and smoothness.
The following moving average has a simple adjustable weighting function that allows the user to have control over the lag and smoothness of the moving average, we will see that it can also be used to get both an SMA and WMA.
A high-resolution gradient is also used to color the moving average, makes it fun to watch, the plot transition between 200 colors, would be tedious to make but everything was made possible using a custom R script, I only needed to copy and paste the R console output in the Pine editor.
Settings
length : Period of the moving average
-Lag : Setting decreasing the lag of the moving average
+Lag : Setting increasing the lag of the moving average
Estimating Existing Moving Averages
The weighting function of this moving average is derived from the calculation of the beta distribution, advantages of such distribution is that unlike a lot of PDF, the beta distribution is defined within a specific range of values (0,1). Parameters alpha and beta controls the shape of the distribution, with alpha introducing negative skewness and beta introducing positive skewness, while higher values of alpha and beta increase kurtosis.
Here -Lag is directly associated to beta while +Lag is associated with alpha . When alpha = beta = 1 the distribution is uniform, and as such can be used to compute a simple moving average.
Moving average with -Lag = +Lag = 1 , its impulse response is shown below.
It is also possible to get a WMA by increasing -Lag , thus having -Lag = 2 and +Lag = 1 .
Using values of -Lag and +Lag equal to each other allows us to get a symmetrical impulse response, increasing these two values controls the heaviness of the tails of the impulse response.
Here -Lag = +Lag = 3 , note that when the impulse response of a moving average is symmetrical its lag is equal to (length-1)/2 .
As for the gradient, the color is determined by the value of an RSI using the moving average as input.
I don't promise anything but I will try to respond to your comments
Band-Pass FilterJust a clean script that can be applied on top of other indicators/sources or you can take the function out of the source and use it in other scripts.
The idea for this was taken from www.pinecoders.com except I am utilizing an EMA instead of SMA. Simply put, we are combining a low-pass filter (moving average) with a high-pass filter (smoothed difference between the source and moving average). The result is a filter/moving average that provides a great combination of minimizing noise while still reacting strongly to price and trend changes.
I like to use this filter in place of other MAs in Pine Scripts to smooth my data. So instead of doing something like sma(stochastic,5) I can easily plug in bp(stochastic,5). It works just fine for your primary moving averages against price as well.
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 !
Grover Llorens Cycle Oscillator [alexgrover & Lucía Llorens]Cycles represent relatively smooth fluctuations with mean 0 and of varying period and amplitude, their estimation using technical indicators has always been a major task. In the additive model of price, the cycle is a component :
Price = Trend + Cycle + Noise
Based on this model we can deduce that :
Cycle = Price - Trend - Noise
The indicators specialized on the estimation of cycles are oscillators, some like bandpass filters aim to return a correct estimate of the cycles, while others might only show a deformation of them, this can be done in order to maximize the visualization of the cycles.
Today an oscillator who aim to maximize the visualization of the cycles is presented, the oscillator is based on the difference between the price and the previously proposed Grover Llorens activator indicator. A relative strength index is then applied to this difference in order to minimize the change of amplitude in the cycles.
The Indicator
The indicator include the length and mult settings used by the Grover Llorens activator. Length control the rate of convergence of the activator, lower values of length will output cycles of a faster period.
here length = 50
Mult is responsible for maximizing the visualization of the cycles, low values of mult will return a less cyclical output.
Here mult = 1
Finally you can smooth the indicator output if you want (smooth by default), you can uncheck the option if you want a noisy output.
The smoothing amount is also linked with the period of the rsi.
Here the smoothing amount = 100.
Conclusion
An oscillator based on the recently posted Grover Llorens activator has been proposed. The oscillator aim to maximize the visualization of cycles.
Maximizing the visualization of cycles don't comes with no cost, the indicator output can be uncorrelated with the actual cycles or can return cycles that are not present in the price. Other problems arises from the indicator settings, because cycles are of a time-varying periods it isn't optimal to use fixed length oscillators for their estimation.
Thanks for reading !
If my work has ever been of use to you you can donate, addresses on my signature :)
Grand Trend Forecasting - A Simple And Original Approach Today we'll link time series forecasting with signal processing in order to provide an original and funny trend forecasting method, the post share lot of information, if you just want to see how to use the indicator then go to the section "Using The Indicator".
Time series forecasting is an area dealing with the prediction of future values of a series by using a specific model, the model is the main tool that is used for forecasting, and is often an expression based on a set of predictor terms and parameters, for example the linear regression (model) is a 1st order polynomial (expression) using 2 parameters and a predictor variable ax + b . Today we won't be using the linear regression nor the LSMA.
In time series analysis we can describe the time series with a model, in the case of the closing price a simple model could be as follows :
Price = Trend + Cycles + Noise
The variables of the model are the components, such model is additive since we add the component with each others, we should be familiar with each components of the model, the trend represent a simple long term variation of high amplitude, the cycles are periodic fluctuations centered around 0 of varying period and amplitude, the noise component represent shorter term irregular variations with mean 0.
As a trader we are mostly interested by the cycles and the trend, altho the cycles are relatively more technical to trade and can constitute parasitic fluctuations (think about retracements in a trend affecting your trend indicator, causing potential false signals).
If you are curious, in signal processing combining components has a specific name, "synthesis" , here we are dealing with additive synthesis, other type of synthesis are more specific to audio processing and are relatively more complex, but could be used in technical analysis.
So what to do with our components ? If we want to trade the trend, we should estimate right ? Estimating the trend component involve removing the cycle and noise component from the price, if you have read stuff about filters you should know where i'am going, yep, we should use filters, in the case of keeping the trend we can use a simple moving average of relatively high period, and here we go.
However the lag problem, which is recurrent, come back again, we end up with information easier to interpret (here the trend, which is a simple fluctuation such as a line or other smooth curve) at the cost of decision timing, that is unfortunate but as i said the information, here the moving average output, is relatively simple, and could be easily forecasted right ? If you plot a moving average of high period it would be easier for you to forecast its future values. And thats what we aim to do today, provide an estimate of the trend that should be easy to forecast, and should fit to the price relatively well in order to produce forecast that could determine the position of future closing prices observations.
Estimating And Forecasting The Trend
The parameter of the indicator dealing with the estimation of the trend is length , with higher values of length attenuating the cycle and noise component in the price, note however that high values of length can return a really long term trend unlike a simple moving average, so a small value of length, 14 for example can still produce relatively correct estimate of trend.
here length = 14.
The rough estimate of the trend is t in the code, and is an IIR filter, that is, it is based on recursion. Now i'll pass on the filter design explanation but in short, weights are constants, with higher weights allocated to the previous length values of the filter, you can see on the code that the first part of t is similar to an exponential moving average with :
t(n) = 0.9t(n-length) + 0.1*Price
However while the EMA only use the precedent value for the recursion, here we use the precedent length value, this would just output a noisy and really slow output, therefore in order to create a better fit we add : 0.9*(t(n-length) - t(n-2length)) , and this create the rough trend estimate that you can see in blue. On the parameters, 0.9 is used since it gives the best estimate in my opinion, higher values would create more periodic output and lower values would just create a rougher output.
The blue line still contain a residual of the cycle/noise component, this is why it is smoothed with a simple moving average of period length. If you are curious, a filter estimating the trend but still containing noisy fluctuations is called "Notch" filter, such filter would depending on the cutoff remove/attenuate mid term cyclic fluctuations while preserving the trend and the noise, its the opposite of a bandpass filter.
In order to forecast values, we simply sum our trend estimate with the trend estimate change with period equal to the forecasting horizon period, this is a really really simple forecasting method, but it can produce decent results, it can also allows the forecast to start from the last point of the trend estimate.
Using The Indicator
We explained the length parameter in the precedent section, src is the input series which the trend is estimated, forecast determine the forecasting horizon, recommend values for forecast should be equal to length, length/2 or length*2, altho i strongly recommend length.
here length and forecast are both equal to 14 .
The corrective parameter affect the trend estimate, it reduce the overshoot and can led to a curve that might fit better to the price.
The indicator with the non corrective version above, and the corrective one below.
The source parameter determine the source of the forecast, when "Noisy" is selected the source is the blue line, and produce a noisy forecast, when "Smooth" is selected the source is the moving average of t , this create a smoother forecast.
The width interval control...the width of the intervals, they can be seen above and under the forecast plot, they are constructed by adding/subtracting the forecast with the forecast moving average absolute error with respect to the price. Prediction intervals are often associated with a probability (determining the probability of future values being between the interval) here we can't determine such probability with accuracy, this require (i think) an analysis of the forecasting distribution as well as assumptions on the distribution of the forecasting error.
Finally it is possible to see historical forecasts, that is, forecasts previously generated by checking the "Show Historical Forecasts" option.
Examples
Good forecasts mostly occur when the price is close to the trend estimate, this include the following highlighted periods on AMD 15TF with default settings :
We can see the same thing at the end of EURUSD :
However we can't always obtain suitable fits, here it is isn't sufficient on BTCUSD :
We can see wide intervals, we could change length or use the corrective option to get better results, another option is to use a log scale.
We will end the examples with the log SPX, who posses a linear trend, so for example a linear model such as a linear regression would be really adapted, lets see how the indicator perform :
Not a great fit, we could try to use an higher length value and use "Smooth" :
Most recent fits are quite decent.
Conclusions
A forecasting indicator has been presented in this post. The indicator use an original approach toward estimating the trend component in the closing price. Of course i should have given statistics related to the forecasting error, however such analysis is worth doing with better methods and in more advanced environment allowing for optimization.
But we have learned some stuff related to signal processing as well as time series analysis, seeing a time series as the sum of various components is really helpful when it comes to make sense of chaotic and noisy series and is a basic topic in time series analysis.
You can see that in this new year i work harder on the visual of my indicators without trying to fall in the label addict trap, something that i wasn't really doing before, let me know what do you think of it.
Thanks for reading !
Windowed Volume Weighted Moving AverageIntroduction
The concept of windowing was briefly introduced in the Blackman filter post, however windowing is more than just some window functions, and isn't exclusively used in filter design.
Today we will use windowing with the volume weighted moving average, a moving average that weight the price with volume in order to be more reactive when volume is high, that is the moving average is more reactive when the market is more active. The use of windowing in the vwma allow to enhance its performance in the frequency domain which result in a smoother output.
Note that i made a similar indicator long ago, but at that time I was not great at all with math and pinescript in general and the indicator was therefore wrong, i want to remind to the community that i'am not a professional, only an enthusiast, I never claimed to be a master coder and i'am totally open to receive criticism, if I sounded like bragging in the past I apologize, at 20 years old it is still easy to act like a kid, the information contained in my posts is only shared in order to help others but also myself, since sharing is also a way to learn more effectively. That said lets go with the indicator.
Windowing
Windowing consist on applying a window function to a signal, by applying i mostly talk about multiplying, this process is mostly used with windowed sinc filters in order to reduce ripples in the pass/stop band, but can be used with any kind of filters in order to have better frequency domain performance, the only thing we need to do is to multiply the filter weights by a window function.
In order to understand windowing it is useful to visualize this process and understand spectral leakage. Remember that we can describe a signal as the sum of sine/cosine waves of different frequencies, amplitude and phase, leakage is an effect that appear with signals having discontinuities, that is when a signal non periodic.
This figure show a non periodic sine wave of frequency 0.1, a non periodic signal will have is last sample value different from its first sample value, if we where to do its fourier transform we wouldn't end up with a single bin at 0.1 but with more bins, this is spectral leakage, the discontinuities in the signal create additional frequency components. In order to reduce leakage we must make the signal approximately periodic, this is done by making use of window functions.
A window function is symmetric and relatively smooth, all we have to do is to multiply our first non periodic signal with the window function.
We end up with the following windowed signal :
The signal is approximately periodic and leakage has been reduced. Now that we have seen that, it might be useful to see why it is useful in filters.
Remember that the Fourier transform of the filter weights gives us its frequency response, if our weights introduce leakage we end up with ripples, so windowing the filter weights might help reduce the ripples in the frequency response, which result in a smoother filter output.
Volume Weighted Moving Average
A volume weighted moving average is a FIR filter who use volume as filter kernel, therefore the frequency response of this filter always change, it is therefore not wrong to qualify the vwma as an adaptive moving average. Higher volume mean higher weighting of the current closing price value, which therefore produce a more reactive output.
However the smoothness of the moving average is relatively poor.
Windowed Volume Weighted Moving Average
The proposed moving average has a length setting who control the moving average period, and various options that we will describe below. The first option is the type of window, there are many windows, certains more complex than others, here 3 windows are proposed, the famous Blackman window, the Bartlett, and finally the Hanning window, they provide each different level of smoothness. lets compare our moving average with period 100 with a vwma of the same period.
Our moving average in red, and the vwma in blue. As you can see the results are smoother.
The power parameter is used in order to give an even higher weighting to closing prices with high volume, this create a more boxy output. Below is a comparison with a vwma in blue and a powered vwma in red with power = 2 without windowing :
We can then apply a window, here i will choose the Blackman window :
Conclusion
A new moving average based on windowed volume weighting has been proposed. The result are smoother which might therefore reduce whipsaw trades. I wish i could have explained things better, unfortunately windowing isn't something i use much, i wanted to post this moving average earlier this year.
I will be off in France for 1 week, my flight is tomorrow in the morning, therefore i don't think i'll have the possibility to make other posts this year. I want to profit from this occasion to review my year in tradingview.
Many indicators have been posted, some being extremely bad and others really interesting, this year introduced my attempts on estimating the lsma efficiently, the linear channels, an attempt on making lines and remain the first indicator from the v4 i posted if i'am right. Then came the efficient auto-line, who gained some popularity quite fast. Then finally the %G oscillator and the recursive bands where posted, and remain some of the favorites indicators i made. I also wanted to leave this year due to studies, that i totally abandoned, i'am thankful that i chosen to stay.
I also want to express my apologies to any member that i could have offended, i think that i'am not a mean person but i certainly not contest the fact that i'am clumsy, even in my work, however my clumsiness is far greater when it comes to interact with other peoples or a group of peoples, i don't want to hurt anyone, if i made anything that made you feel bad then i'am sincerely sorry, and hope we can start this new year from 0.
Finally i thank the tradingview community for their interest and curiosity, i thank all the great coders who work on making pinescript a better scripting language, i also thank the tradingview staff for their work this year. I wish you all a merry christmas, and an happy new year.
Thanks for reading.
Blackman Filter - The Smoother The BetterIntroduction
Who doesn't like smooth things? I'd like a smooth market price for christmas! But i can't get it, instead its so noisy...so you apply a filter to smooth it, such filters are called low-pass filters, they smooth and its great but they have lag, so nobody really use them, but they are pretty to look at.
Its on a childish note that i will introduce this indicator, so what it is all about? I propose a new FIR filter using a blackman function as filter kernel for financial time-series smoothing, do you prefer the childish tone ? Fear not its surprisingly easy!
The Blackman Function
The blackman function look like a bell shaped curve, look:
The blackman function will produce such curve. This function is called a cosine sum function because she is based on the sum of cosine functions, here only 2.
0.42 - 0.5 * cos(2 * pi * k) + 0.08 * cos(4 * pi * k)
Originally you use this function for windowing , what does it means? In signal processing you have a function called sync function , if you use this function as filter kernel you would get the ideal frequency domain response filter, sometime called brickwall filter, it would be extremely smooth.
Above the optimal low pass filter frequency response.
However the sync function has no ending values and goes on forever, therefore we can't use it for convolution, expect if we apply windowing. Filters using windowing are called windowed-sinc filters, i will describe the procedure below :
1 - Create a sync function = sin(pi*n)/(pi*n)
2 - Truncate it = I only keep the first length points of the sync function.
This create a abrupt end, the frequency of a filter using step 1 as kernel would contain ripples in the pass band and stop band, this is bad! The frequency response would look like this :
3 - I multiply my values of step 2 by a window function, it can the blackman window, i no longer have an abrupt end, its smooth!
The frequency response of the filter using this kernel would no longer have ripples! This is the power of windowing functions.
Here we are not using such thing, but we could in the future. Here instead we use the blackman function as filter kernel, because this function is bell shaped this mean that the filter will certainly be smooth (symmetrical weighting is a rule of thumb for kernels when we want really smooth filters).
The Filter
This filter is quite smooth, unlike the gaussian filter this filter give less weights to recent and past values, this is because the blackman function has fatter tails than the gaussian one. I could make a comparison of both, however they are quite alike, if you often use a gaussian filter its up to you to decide which one you prefer.
The filter can do a better job than the moving average when it comes to preserve the frequency components that constitute the cycles/trend.
We can see that the filter has a greater performance when it comes to keep the shape of the market price, thus it has a slightly better fit.
Conclusion
Ok so in this post you learned a bit about the sync function and windowing, those are basic subjects in signal processing, they allow us to approximate the filter with the ideal frequency response, i also showed you that those windowing function could be used as kernel and that they where pretty smooth on their own, there are many others, but the one i prefer is the blackman windowing function.
I know what you are thinking, "we want trailing stops, alerts, colors, arrows!", and i understand you pal, but sometimes its cool to take a break from all this stuff. However i can tell that i'am working on a side project that aim to estimate rolling maximum/minimum as fast as possible, any experiments will be published here, and i can ensure you that those indicators will make your day quite brighter, we will see that soon.
I hope you learned something from this post! I'am a bit tired (look i'am disappearing !)
Thanks for reading !
Kaufman Adaptive Correlation OscillatorIntroduction
The correlation oscillator is a technical indicator that measure the linear relationship between the market closing price and a simple increasing line, the indicator is in a (-1,1) range and rise when price is up-trending and fall when price is down-trending. Another characteristic of the indicator is its inherent smoothing which provide a noise free (to some extent) oscillator.
Such indicator use simple moving averages as well as estimates of the standard deviation for its calculation, but we can easily make it adaptive, this is why i propose this new technical indicator that create an adaptive correlation oscillator based on the Kaufman adaptive moving average.
The Indicator
The length parameter control the period window of the moving average, larger periods return smoother results while having a low kurtosis, which mean that values will remain around 1 or -1 a longer period of time. Pre-filtering apply a Kaufman adaptive moving average to the input, which allow for a smoother output.
No pre-filtering in orange, pre-filtering in yellow, period = 100 for both oscillators.
If you are not aware of the Kaufman adaptive moving average, such moving average return more reactive results when price is trending and smoother results when price is ranging, this also apply for the proposed indicator.
Conclusion
Classical correlation coefficients could use this approach, therefore the linear relationships between any variables could be measured. The fact that the indicator is adaptive add a certain potential, however such combination make the indicator have the drawback of kama + the correlation oscillator, which might appear at certain points.
Thanks for reading !
Turbo Scaler - The Art Of Being (too) EarlyIntroduction
Fast smooth indicators that produce early signals can sound utopic but mathematically its not a huge deal, the effect of early outputs based on smooth inputs can be seen on differentiators crosses, this is why i propose this indicator that aim to return extra fast signals based on a slightly modified max-min normalization method. The indicator introduce inherent smoothing without having an huge impact on the indicator reactivity.
The Indicator
The indicator is based on max-min normalization (like the stochastic oscillator) however instead of using the highest/lowest of the input we use the highest and lowest of the moving average of the input. This process using as input the closing price and the moving average closing price will return two lines, and because of the nature of max-min normalization we can see that the trigger line (in orange) produce earlier crosses. length control the highest/lowest period while smooth control the output lines smoothness (50 by default).
alpha control the scaling amount, with higher values of alpha creating more constrained scale, when alpha = 1 the scale is in a range of (0,1) while lower values of alpha can make the output move more freely.
alpha = 0.25
alpha = 1
Higher values of alpha create earlier signals.
Downsides Of Early Crosses
Of course such indicator make us exposed to the trend as seen below.
We can nonetheless protect ourselves against such cases scenarios by lowering alpha.
lowering alpha allow to catch movements of the trend without loosing much reactivity at the cost of an increased umber of trades.
Possible Uses
The proposed indicator allow for an high number of uses because of its scale, reactive nature...etc. A method that allow us to go with the main trend is by taking into account the crosses between the lines and the sign of the lines, for example :
The first signal (green) happen when the main line (in blue) crossover the trigger (orange) while both are > 0, the same happen with the second signal however both lines are < 0. This method can use certain levels instead of the sign (main line crossover trigger while both > 0.7...etc).
This method is great for the indicator because such cases scenarios does not happen a lot with ranging markets, we can clearly that when trending the trigger can have the tendency to be flat and higher than 0 thus allowing for the main line to produce those signals.
Conclusion
I have presented a super reactive crosses indicator based on max-min normalization with the ability to both be smooth and produce early entries/exits signals, different methods have been presented in order to allow for different setups using this indicator.
The introduction of the alpha parameter allow for more control which is what those kind of indicators needs. I hope you find an use to it :)
Support Me
Making indicators sure is hard, it takes time and it can be quite lonely to, so i would love talking with you guys while making them :) There isn't better support than the one provided by your friends so drop me a message.
Powered Kaufman Adaptive Moving AverageIntroduction
The ability the Kaufman adaptive moving average (KAMA) has to be flat during ranging markets and close to the price during trending markets is what make this moving average one of the most useful in technical analysis. KAMA is calculated by using exponential averaging using the efficiency ratio (ER) as smoothing variable where 1 > ER > 0 . An increasing efficiency ratio indicate a trending market. Based on one of my latest indicator (see Kaufman Adaptive Bands) i propose this modified KAMA that allow to emphasis the abilities of KAMA by powering the efficiency ratio. I also added a new option that allow for even more adaptivity.
The Indicator
The indicator is a simple KAMA of period length that use a powered ER with exponent factor .
When factor = 1 the indicator is a simple KAMA, however when factor > 1 there can be more emphasis on the flattening effect of KAMA.
You can also restrain this effect by using 1 > factor > 0
Note that when the exponent is lower than 1 and greater than 0 you are basically applying a nth square root to the value, for example pow(2,0.5) = sqrt(2) because 1/0.5 = 2, in our case :
pow(ER,factor > 1) < ER and pow(ER,1 > factor > 0) > ER
Self Powered P-KAMA
When the self powered option is checked you are basically powering ER with the reciprocal of ER as exponent, however factor does no longer change anything. This can give interesting results since the exponent depend on the market trend strength.
In orange the self powered KAMA of period length = 50 and in blue a basic powered KAMA with a factor of 3 and a period of length = 50.
Conclusion
Applying basic math to indicators is always fun and easy to do, if you have adaptive moving averages using exponential averaging try powering your smoothing variable in order to see interesting results. I hope you like this indicator. Thanks for reading !
Motion Smoothness Index Introduction
Its holiday time for me, i have been working here a lot. But no leaving before publishing. Telling when market price is smooth or rough is not the easiest task, so today i present a trend metric indicator that allow you to give you this kind of information.
The Indicator
The indicator is in an approximate range of (0,1) with mean x̄ decaying for higher length's, when the indicator is below 0.5 the market is smooth, else rough, this is the simple interpretation. The indicator is simply the ratio of the price residual standard deviation and the price standard deviation.
Higher value of length will make the indicator less accurate when it comes to detect rough market price, you can still use the indicator direction or its running mean to give you insights but 0.5 is still the recommended detection threshold.
In More Depth
Even tho market is random by nature there can still be structures in the price (cycles and trends), the fractional BM model will tell you that market price is sometimes auto-correlated (trending) or non auto-correlated (ranging), knowing what is the current market state is therefore important, when price is rough it can means an excess in noise thus exhibiting an uncorrelated market at the contrary of a smoother price that can allow for auto-correlation.
Now, market is infected by noise, and thats really unfortunate but the noise posses various properties that can allow for all the structures we see in market price. So thinking about the market allowing for possible profits during auto-correlated states is encouraging.
Conclusion
Although the indicator measure smoothness/roughness it can still be interpreted as a trend/range state detector. I hope it provide to be useful.
I wish you all good holidays and see you next time ! Thanks for reading !
Hybrid Convolution FilterIntroduction
Today i propose an hybrid filter that use a classical FIR architecture while using recursion. The proposed method aim to reduce the lag generated by fir filters. This particular filter is a sine weighted moving average, but you can change it since the indicator is built with the custom filter template (1). Even if it use recursion it still is a FIR filter since the impulse response is finite.
The Indicator
In red the hybrid swma and in blue the classic swma of both the same period. The difference can be seen.
The switch between the input price and the past values of the previous convolution values is made by using exponential averaging, the window function is the same as f(x) in the code.
Any filter can use this architecture, the indicator is built around the custom fir template, see (1)
Conclusion
I presented a FIR filter using recursion in its calculation, the integration is made with respect to the proposed template, therefore any user can simply modify f(x) to have different filter without the need to make any change. However curious users might want to change the window function of the exponential averager, in order to do so change sgn = f(i/length) in line 11 for sgn = fun(i/length) where fun is your custom function, make sure to add it at the start of the script where all the other functions declarations are.
Thanks for reading !
(1)
Bilateral Stochastic Oscillator - For The Sake Of EfficiencyIntroduction
The stochastic oscillator is a feature scaling method commonly used in technical analysis, this method is the same as the running min-max normalization method except that the stochastic oscillator is in a range of (0,100) while min-max normalization is in a range of (0,1). The stochastic oscillator in itself is efficient since it tell's us when the price reached its highest/lowest or crossed this average, however there could be ways to further develop the stochastic oscillator, this is why i propose this new indicator that aim to show all the information a classical stochastic oscillator would give with some additional features.
Min-Max Derivation
The min-max normalization of the price is calculated as follow : (price - min)/(max - min) , this calculation is efficient but there is alternates forms such as :
price - (max - min) - min/(max - min)
This alternate form is the one i chosen to make the indicator except that both range (max - min) are smoothed with a simple moving average, there are also additional modifications that you can see on the code.
The Indicator
The indicator return two main lines, in blue the bull line who show the buying force and in red the bear line who show the selling force.
An orange line show the signal line who represent the moving average of the max(bull,bear), this line aim to show possible exit/reversals points for the current trend.
Length control the highest/lowest period as well as the smoothing amount, signal length control the moving average period of the signal line, the pre-filtering setting indicate which smoothing method will be used to smooth the input source before applying normalization.
The default pre-filtering method is the sma.
The ema method is slightly faster as you can see above.
The triangular moving average is the moving average of another moving average, the impulse response of this filter is a triangular function hence its name. This moving average is really smooth.
The lsma or least squares moving average is the fastest moving average used in this indicator, this filter try to best fit a linear function to the data in a certain window by using the least squares method.
No filtering will use the source price without prior smoothing for the indicator calculation.
Relationship With The Stochastic Oscillator
The crosses between the bull and bear line mean that the stochastic oscillator crossed the 50 level. When the Bull line is equal to 0 this mean that the stochastic oscillator is equal to 0 while a bear line equal to 0 mean a stochastic oscillator equal to 100.
The indicator and below a stochastic oscillator of both period 100
Using Levels
Unlike a stochastic oscillator who would clip at the 0 and 100 level the proposed indicator is not heavily constrained in a range like the stochastic oscillator, this mean that you can apply levels to trigger signals
Possible levels could be 1,2,3... even if the indicator rarely go over 3.
Its then possible to create strategies using such levels as support or resistance one.
Conclusion
I've showed a modified stochastic oscillator who aim to show additional information to the user while keeping all the information a classical stochastic oscillator would give. The proposed indicator is no longer constrained in an hard range and posses more liberty to exploit its scale which in return allow to create strategies based on levels.
For pinescript users what you can learn from this is that alternates forms of specific formulas can be extremely interesting to modify, changes can be really surprising so if you are feeling stuck, modifying alternates forms of know indicators can give great results, use tools such as sympy gamma to get alternates forms of formulas.
Thanks for reading !
If you are looking for something or just want to say thanks try to pm me :)
Fisher Least Squares Moving AverageIntroduction
I already estimated the least-squares moving average numerous times, one of the most elegant ways was by rescaling a linear function to the price by using the z-score, today i will propose a new smoother (FLSMA) based on the line rescaling approach and the inverse fisher transform of a scaled moving average error with the goal to provide an alternative least-squares smoother, the indicator won't use the correlation coefficient and will try to adresses problems such as overshoots and lag reduction.
Line Rescaling Method
For those who did not see my least squares moving average estimation using the line rescaling method here is a resume, we want to fit a polynomial function of degree 1 to the price by reducing the sum of squares between the price and the filter, squares is a term meaning the squared difference between the price and its estimation. The line rescaling technique work as follow :
1 - get the z-score of a line.
2 - multiply this z-score with the correlation between the price and a line.
3 - multiply the precedent result with the standard deviation of the price, then sum that to a simple moving average.
This process is shorter than the classical least-squares moving average method.
Z-Score Derivation And The Inverse Fisher Transform
The FLSMA will use a similar approach to the line rescaling technique but instead of using the correlation during step 2 we will use an alternative calculated from the error between the estimate and the price.
In order to do so we must use the inverse fisher transform, the inverse fisher transform can take a z-score and scale it in a range of (1,-1), it is possible to estimate the correlation with it. First lets create our modified z-score in the form of : Z = ma((y - Y)/e) where y is the price, Y our output estimate and e the moving average absolute error between the price and Y and lets call it scaled smoothed error , then apply the inverse fisher transform : r = IFT(Z) = tanh(Z) , we then multiply the z-score of the line with it.
Performance
The FLSMA greatly reduce the overshoots, this mean that the maximas of abs(r) are lower than the maxima's of the absolute correlation, such case is not "bad" but we can see that the filter is not closer to the price than the LSMA during trending periods, we can assume the filter don't reduce least-squares as well as the LSMA.
The image above is the running mean of the absolute error of each the FLSMA (in red) and the LSMA (in blue), we could fix this problem by multiplying the smooth scaled error by p where p can be any number, for example :
z = sma(src - nz(b ,src),length)/e * p where p = 2
In red the FLSMA and in blue the FLSMA with p = 2 , the greater p is the less lag the FLSMA will have.
Conclusion
It could be possible to get better results than the LSMA with such design, the presented indicator use its own correlation replacement but it is possible to use anything in a range of (1,-1) to multiply the line z-score. Although the proposed filter only reduce overshoots without keeping the accuracy of the LSMA i believe the code can be useful for others.
Thanks for reading.
SVAMA - A Non Parametric Adaptive Moving Average Based On VolumeIntroduction
Technical indicators often have parameters settings that the user must enter, those are inconvenient when the user must design a strategy because such settings must be optimized, it must also been noted that the optimal settings at time t could change at time t+n , this is why non parametric indicators are more efficient. Today i propose a moving average adapting to the market volume without using parameters affecting the smoothing.
The Indicator
The volume is rescaled in a range of (1,0) by using max or min normalization. Exponential averaging is used to provide the moving average.
When using max normalization the moving average react faster when the volume is closer to its all time high, when using min normalization the moving average react faster when the volume is closer to its all time low. You can select the method (max or min) from the "Method" parameter.
Volume tend to be higher and more periodic with higher time-frames, this is why lower time-frames might return smoother results when using the Max method. It is recommended to use the Max method when we want a faster moving average while the Min method is more suited to get a slower moving average.
Both methods can provide an interesting MA-Cross system when used on higher time frames.
Conclusion
There should be more non parametric indicators, this would allow for faster and easier optimization processes when creating a strategy, in theory any indicator using a moving average or highest/lowest could be made non parametric by using a running mean or running max/min but the indicator might loose important information.
This is one of my main focus right now since such indicators could also allow for improvements when used with artificial intelligence. I hope you find an use to it, don't hesitate to send me your suggestions.
Thanks for reading !