Ehlers Ideal RSIThis script has been updated to Pine v4. Original script by JustUncleL (link in code)
Adaptive
Autonomous Recursive Moving AverageIntroduction
People often ask me what is my best indicators, i can't really respond to this question with a straight answer but i would say you to check this indicator. The Autonomous Recursive Moving Average (ARMA) is an adaptive moving average that try to minimize the sum of squares thanks to a ternary operator, this choice can seem surprising since most of the adaptive moving averages adapt to a smoothing variable thanks to exponential averaging, but there are lot of downsides to this method, i really wanted to have a flat filter during flat markets and this is what i achieved.
The Indicator
length control the amount of smoothing during trending periods, gamma is the trend sensitivity threshold, higher values of gamma will make an overall flat filter, adjust gamma to skip ranging markets.
gamma = 2, we can adjust to 3 while preserving smoothing reactivity with trading periods.
gamma = 3
low length and higher gamma create more boxy result, the filter add overshoots directly in the output, its unfortunate.
The Zero-Lag option can reduce the lag as well as getting additional flat results without changing gamma.
Conclusion
The indicator need work, but i can't leave without publishing it, the overshoots are a big problems, changing sma for another stable filter can help. I hope you find an use to it, i really like this indicator.
Thanks for reading
Ratio OCHL Averager - An Alternative to VWAPIntroduction
I had the idea to make this indicator thanks to @dpanday with the support of @Coppermine and @Reika. Vwap is a non parametric indicator based on volume used by lot of traders and institutions, its non parametric particularity makes it great because it don't need to go through parameter optimization. Today i present a similar indicator called Ratio OCHL Averager based on exponential averaging by using the ratio of open-close to high-low range by using monthly high/low.
The Indicator
The indicator can more recursive by checking the "recursive" option, this allow to use the indicator output instead of the open price for the calculation of the ratio of open-close to high-low range. The result is a more reactive estimation,
The indicator reactivity change based on the time frame you are in, using higher time frame result in a more reactive indicator, however it is way less reactive than the vwap, this is a personal choice since i wanted this indicator to be smooth even with high time frames, if you want to change that you use another resolution for H and L in line 5,6.
Conclusion
I presented an alternative to vwap based on the Ratio OCHL indicator. I hope you like it and thanks for reading !
Thanks to Coppermine and Reika for the support during the creation of the indicator
Volume Adaptive BandsIntroduction
I have been asked by @Coppermine and @Verbena to make bands that use volume to provide adaptive results. My first approach was to use exponential averaging, in order to do so i needed to quantify volume movement using rescaling with the objective to make the bands go away from each others when there is low volume, this approach is efficient and can work on any time frame, however i decided at the end to use another method which rely on recursive weighting, cleaner but more parametric. Those bands aim to highlight great breakouts point to go with the trend.
The Indicator
length control the period of the moving averages used in the script, however low length's don't necessarily provide indications for shorter terms breakouts as shown here :
As i said the bands are close to each others when there is high volume and away when there is low volumes.
Low volume period, bands will avoid to cross price
High volume, bands will be close to generate signals.
Correction Factor
Higher time frames will lower the distance between each band, this is because volume is higher during higher time frames, remember that the indicator bands are close to each others when volume is high.
1h chart eurusd.
This is why i added a correction factor, this factor can help you control the distance between each bands, when the correction factor is greater than 1 the bands will be closer to each others, this is useful for low time frames where the average volume is lower. When the time frame is high, use values between 0 and 1 to increase distance between each bands.
Correction factor = 0.2
Conclusion
I presented a new adaptive band indicator that adapt to trading volume by using recursive weighting, volume can be replaced by other indicators but you can have results going nuts, at the end its about experimentation. I hope you will find an use to it, thanks to @Coppermine and @Verbena for the request :)
Thanks for reading !
Non Parametric Adaptive Moving AverageIntroduction
Not be confused with non-parametric statistics, i define a "non-parametric" indicator as an indicator who does not have any parameter input. Such indicators can be useful since they don't need to go through parameter optimization. I present here a non parametric adaptive moving average based on exponential averaging using a modified ratio of open-close to high-low range indicator as smoothing variable.
The Indicator
The ratio of open-close to high-low range is a measurement involving calculating the ratio between the absolute close/open price difference and the range (high - low) , now the relationship between high/low and open/close price has been studied in econometrics for some time but there are no reason that the ohlc range ratio may be an indicator of volatility, however we can make the hypothesis that trending markets contain less indecision than ranging market and that indecision is measured by the high/low movements, this is an idea that i've heard various time.
Since the range is always greater than the absolute close/open difference we have a scaled smoothing variable in a range of 0/1, this allow to perform exponential averaging. The ratio of open-close to high-low range is calculated using the vwap of the close/high/low/open price in order to increase the smoothing effect. The vwap tend to smooth more with low time frames than higher ones, since the indicator use vwap for the calculation of its smoothing variable, smoothing may differ depending on the time frame you are in.
1 minute tf
1 hour tf
Conclusion
Making non parametric indicators is quite efficient, but they wont necessarily outperform classical parametric indicators. I also presented a modified version of the ratio of open-close to high-low range who can provide a smoothing variable for exponential averaging. I hope the indicator can help you in any way.
Thanks for reading !
Dynamically Adjustable FilterIntroduction
Inspired from the Kalman filter this indicator aim to provide a good result in term of smoothness and reactivity while letting the user the option to increase/decrease smoothing.
Optimality And Dynamical Adjustment
This indicator is constructed in the same manner as many adaptive moving averages by using exponential averaging with a smoothing variable, this is described by :
x= x_1 + a(y - x_1)
where y is the input price (measurements) and a is the smoothing variable, with Kalman filters a is often replaced by K or Kalman Gain , this Gain is what adjust the estimate to the measurements. In the indicator K is calculated as follow :
K = Absolute Error of the estimate/(Absolute Error of the estimate + Measurements Dispersion * length)
The error of the estimate is just the absolute difference between the measurements and the estimate, the dispersion is the measurements standard deviation and length is a parameter controlling smoothness. K adjust to price volatility and try to provide a good estimate no matter the size of length . In order to increase reactivity the price input (measurements) has been summed with the estimate error.
Now this indicator use a fraction of what a Kalman filter use for its entire calculation, therefore the covariance update has been discarded as well as the extrapolation part.
About parameters length control the filter smoothness, the lag reduction option create more reactive results.
Conclusion
You can create smoothing variables for any adaptive indicator by using the : a/(a+b) form since this operation always return values between 0 and 1 as long as a and b are positive. Hope it help !
Thanks for reading !
Trend Impulse FilterIntroduction
There is a lot of indicators similar to this one, however i think this one don't share the same calculation method and this is why i share it. This indicator aim to forecast price direction using an exponential filter architecture using highest and lowest information for the estimation of a smoothing variable. This filter is similar to the average Max-Min filter.
The Indicator
In the code a is equal to 1 when the price is greater or lower than any past price over length period, else a is equal to 0. The center parameter control the filtering degree of the output, when center is equal to 1 and a = 1 the indicator return the highest or lowest depending on market current trend, when center is superior to 1 the output will be smoother, however the reactivity of the indicator will still depend on the length parameter.
A color option show you the trend of the market, however the generated signals are the same that can be generated from a Donchian channel.
When highest is greater than previous highest the indicator direction will move upward, else if lowest is lower than previous lowest the indicator direction will move downward. Therefore the indicator can give information on the Donchian channels direction and provide a nice filter.
Conclusions
Adapting to highest and lowest can make an indicator adapt to the essence of trend trading, the indicator i showed can be used as source for others indicator or in MA crossover strategies. If you have a strategy using Donchian channels you may be interested in using this indicator and se how it fit in your strategy. Hope you like it.
Thanks for reading !
Falling-Rising FilterIntroduction
This is a modification of an old indicator i made. This filter aim to adapt to market trend by creating a smoothing constant using highest and lowest functions. This filter is visually similar to the edge-preserving filter, this similarity can make this filter quite good for MA cross strategies.
On The Filter Code
a = nz(a ) + alpha*nz(error ) + beta*nz(error )
The first 3 terms describe a simple exponential filter where error = price - a , beta introduce the adaptive part. beta is equal to 1 when the price is greater or lower than any past price over length period, else beta is equal to alpha , someone could ask why we use two smoothing variable (alpha, beta) instead of only beta thus having :
a = nz(a ) + beta*nz(error )
well alpha make the filter converge faster to the price thus having a better estimation.
In blue the filter using only beta and in red the filter using alpha and beta with both length = 200 , the red filter converge faster to the price, if you need smoother results but less precise estimation only use beta .
Conclusion
I have presented a simple indicator using rising/falling functions to calculate an adaptive filter, this also show that when you create an exponential filter you can use more terms instead of only a = a + alpha*(price - a ) . I hope you find this indicator useful.
Thanks for reading !
Dynamically Adjustable Moving AverageIntroduction
The Dynamically Adjustable Moving Average (AMA) is an adaptive moving average proposed by Jacinta Chan Phooi M’ng (1) originally provided to forecast Asian Tiger's futures markets. AMA adjust to market condition in order to avoid whipsaw trades as well as entering the trending market earlier. This moving average showed better results than classical methods (SMA20, EMA20, MAC, MACD, KAMA, OptSMA) using a classical crossover/under strategy in Asian Tiger's futures from 2014 to 2015.
Dynamically Adjustable Moving Average
AMA adjust to market condition using a non-exponential method, which in itself is not common, AMA is described as follow :
1/v * sum(close,v)
where v = σ/√σ
σ is the price standard deviation.
v is defined as the Efficacy Ratio (not be confounded with the Efficiency Ratio) . As you can see v determine the moving average period, you could resume the formula in pine with sma(close,v) but in pine its not possible to use the function sma with variables for length, however you can derive sma using cumulation.
sma ≈ d/length where d = c - c_length and c = cum(close)
So a moving average can be expressed as the difference of the cumulated price by the cumulated price length period back, this difference is then divided by length. The length period of the indicator should be short since rounded version of v tend to become less variables thus providing less adaptive results.
AMA in Forex Market
In 2014/2015 Major Forex currencies where more persistent than Asian Tiger's Futures (2) , also most traded currency pairs tend to have a strong long-term positive autocorrelation so AMA could have in theory provided good results if we only focus on the long term dependency. AMA has been tested with ASEAN-5 Currencies (3) and still showed good results, however forex is still a tricky market, also there is zero proof that switching to a long term moving average during ranging market avoid whipsaw trades (if you have a paper who prove it please pm me) .
Conclusion
An interesting indicator, however the idea behind it is far from being optimal, so far most adaptive methods tend to focus more in adapting themselves to market complexity than volatility. An interesting approach would have been to determine the validity of a signal by checking the efficacy ratio at time t . Backtesting could be a good way to see if the indicator is still performing well.
References
(1) J.C.P. M’ng, Dynamically adjustable moving average (AMA’) technical
analysis indicator to forecast Asian Tigers’ futures markets, Physica A (2018),
doi.org
(2) www.researchgate.net
(3) www.ncbi.nlm.nih.gov
Edge-Preserving FilterIntroduction
Edge-preserving smoothing is often used in image processing in order to preserve edge information while filtering the remaining signal. I introduce two concepts in this indicator, edge preservation and an adaptive cumulative average allowing for fast edge-signal transition with period increase over time. This filter have nothing to do with classic filters for image processing, those filters use kernels convolution and are most of the time in a spatial domain.
Edge Detection Method
We want to minimize smoothing when an edge is detected, so our first goal is to detect an edge. An edge will be considered as being a peak or a valley, if you recall there is one of my indicator who aim to detect peaks and valley (reference at the bottom of the post) , since this estimation return binary outputs we will use it to tell our filter when to stop filtering.
Filtering Increase By Using Multi Steps Cumulative Average
The edge detection is a binary output, using a exponential smoothing could be possible and certainly more efficient but i wanted instead to try using a cumulative average approach because it smooth more and is a bit more original to use an adaptive architecture using something else than exponential averaging. A cumulative average is defined as the sum of the price and the previous value of the cumulative average and then this result is divided by n with n = number of data points. You could say that a cumulative average is a moving average with a linear increasing period.
So lets call CMA our cumulative average and n our divisor. When an edge is detected CMA = close price and n = 1 , else n is equal to previous n+1 and the CMA act as a normal cumulative average by summing its previous values with the price and dividing the sum by n until a new edge is detected, so there is a "no filtering state" and a "filtering state" with linear period increase transition, this is why its multi-steps.
The Filter
The filter have two parameters, a length parameter and a smooth parameter, length refer to the edge detection sensitivity, small values will detect short terms edges while higher values will detect more long terms edges. Smooth is directly related to the edge detection method, high values of smooth can avoid the detection of some edges.
smooth = 200
smooth = 50
smooth = 3
Conclusion
Preserving the price edges can be useful when it come to allow for reactivity during important price points, such filter can help with moving average crossover methods or can be used as a source for other indicators making those directly dependent of the edge detection.
Rsi with a period of 200 and our filter as source, will cross triggers line when an edge is detected
Feel free to share suggestions ! Thanks for reading !
References
Peak/Valley estimator used for the detection of edges in price.
Bryant Adaptive Moving Average@ChartArt got my attention to this idea.
This type of moving average was originally developed by Michael R. Bryant (Adaptrade Software newsletter, April 2014). Mr. Bryant suggested a new approach, so called Variable Efficiency Ratio (VER), to obtain adaptive behaviour for the moving average. This approach is based on Perry Kaufman' idea with Efficiency Ratio (ER) which was used by Mr. Kaufman to create KAMA.
As result Mr. Bryant got a moving average with adaptive lookback period. This moving average has 3 parameters:
Initial lookback
Trend Parameter
Maximum lookback
The 2nd parameter, Trend Parameter can take any positive or negative value and determines whether the lookback length will increase or decrease with increasing ER.
Changing Trend Parameter we can obtain KAMA' behaviour
To learn more see www.adaptrade.com
MESA Adaptive Moving AverageIntro
One of Ehlers most well-known indicators! I've seen many variations of this on TradingView, however, none seem to be true to the original released by Ehlers himself.
I've taken it upon myself to simply translate the MAMA into Pinescript, instead of re-writing like some others have done.
You can use it as a very effective & adaptive moving average with other signals or
as a standalone signal.
In the case that you're going to use it for signals and not simple technical trading (non-quantitative),
I've also added a threshold parameter to filter out weak signals.
My MAMA indicator is different from others in very simple ways - I don't use the nz() command, which sets all "Not a Number" values to 0. In others' scripts, you immediately load the indicator with several 0 values,
causing a slight lag in future calculations since this code is recursive (refers to previous values it generated).
In my version, I simply wait until the script has access to all the bar data it needs, instead of instantly performing calculations and
setting erroneous values to 0. In this case, we start with the correct values (or closer to correct).
If you want to compare this indicator the current most popular MAMA by LazyBear, you'll notice it often gives buy and sell crosses one bar earlier than theirs.
Setting Parameters
Source - the data series to perform calculations on. (Initially, Ehlers himself favored hl/2, but conceded that there isn't empirical benefit over close.)
Fast Limit - controls how quickly the MAMA will "ratchet up" fast price action. (Higher values are faster)
Slow Limit - controls how closely the FAMA will follow the MAMA. (Again, higher is faster. You typically want the FAMA to be slower though.)
Crossover Threshold - simple error thresholding to limit the number of weak trade signals. (Lower means lower tolerance)
Show Crosses? - show/hide the arrows at moving average crosses
Robust Cycle Measurement [Ehlers]The last of Ehlers Instantaneous Frequency Measurement methods.
This is a more robust version of this script.
I wrote it as a function, so you can simply copy and paste it into any script to add an adaptive period setting capability.
Cheers,
DasanC
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
Adaptive Bandpass Filter [Ehlers]This is my latest bandpass filter - used to determine if a security is in a trend or cycle.
Now with an adaptive period setting! I use Ehlers in-phase & quadrature dominant cycle measurement (IQ IFM) method to set the period dynamically.
This method favors longer periods which tend to produce smoother, albeit laggier bandpass oscillator plots. From my quick tests, I tend to have lag between 4 and 8 bars, depending on the Timeframe.
The lower timeframes tend to have more noise and thus produce more interfering frequencies that may cause lag.
>Settings
Source: Select the data source to perform calc's on (close, open, etc...)
Period: Select the period to tune. Periods outside of this value will be attenuated (reduced)
Adaptive: Enable to have the I-Q IFM set the period for you (disables Period setting)
Bandpass Tolerance: Allow periods that are plus/minus the chosen period to pass.
Cycle Tolerance: Sensitivity of cycle mode. Lower values consider trends more frequent, higher values consider cycles more frequent.
Bandpass tolerance example: for instance, if this setting is 0.1 (10%) and Period is set to 20, then waves with a period of 18 - 22 will pass.
>How to read
Red line is the bandpass output, showing a lagged version of the dominant cycle representing the
Black lines are the upper and lower bounds for a cycle
Green Background indicates an uptrend
Red background indicates a downtrend
Relative Strength Volatility Variable Bands [DW]This is an experimental adaptive trend following study inspired by Giorgos Siligardos's Reverse Engineering RSI and Tushar S. Chande's Variable Moving Average.
In this study, reverse engineered RSI levels are calculated and used to generate a volatility index for VMA calculation.
First, price levels are calculated for when RSI will equal 70 and 30. The difference between the levels is taken and normalized to create the volatility index.
Next, an initial VMA is calculated using the created volatility index. The moving average is an exponential calculation that adjusts the sampling length as volatility changes.
Then, upper and lower VMAs are calculated by taking a VMA of prices above and below the initial VMA. The midline is produced by taking the median of the upper and lower VMAs.
Lastly, the band levels are calculated by multiplying the distance from the midline to the upper and lower VMAs by 1, 2, 3, 4, and 5.
Bar colors are included. They're based on the midline trend and price action relative to the upper and lower VMAs.
Adaptive StochasticAdapt To The Right Situation
There are already some Adaptive Stochastic scripts out there, but i didn't see the concept of using different periods highest/lowest for their calculations. What we want
for such oscillator is to be active when price is trending and silent during range periods. Like that the information we will see will be clear and easy to use.
Switching between a long term highest/lowest during range periods and a short term highest/lowest during trending periods is what will create the adaptive stochastic.
The switching is made thanks to the Efficiency Ratio , the period of the efficiency ratio is determined by the length parameter.
The period of the highest and lowest will depend on the slow and fast parameters, if our efficiency ratio is close to one (trending market) then the indicator will use highest and lowest of period fast , making the indicator more reactive, if our efficiency ratio is low (ranging market) then the indicator will use highest and lowest of period slow , making the indicator less reactive.
The source of the indicator is a running line ( lsma ) of period slow-fast .
it is also possible to switch the parameters values, making the indicator reactive during ranging market and less reactive during trending ones.
Hope you enjoy
For any questions/demands feel free to pm me, i would be happy to help you
Retention-Acceleration FilterAnother Adaptive Filter
This indicator share the same structure as a classic adaptive filter using an exponential window with a smoothing constant.
However the smoothing constant used is different than any previously made (Kalman Gain, Efficiency ratio, Scaled Fractal Dimension Index) ,
here the smoothing constant is inspired by the different formulations for parameters resolution used in HPLC S. Said (J. High Resolution Chromatograpy &Chromatography Communciations, (1979) 193).
Different assumptions can be made which lead to different expressions for resolution in chromatographic parameters, therefore we will use highest's and lowest's in order to estimate an optimal smoothing constant based on if the market is trending or not. It can be complicated at first but the goal is to provide both smoothness at the right time and a fast estimation of the market center.
Handling Noise
In Red a Pure Sinewave. In White Sinewave + Noise. In Blue our filter of Period 3
Handling stationary signals is not the best thing to do since we need highest's and lowest's and for that non stationary signals with trend + cycle + noise are more suitable.
It is also possible to make it act faster by quiting the pow() function of AltK with sqrt(length) and smoothing the remaining constant.
Range Filter [DW]This is an experimental study designed to filter out minor price action for a clearer view of trends.
Inspired by the QQE's volatility filter, this filter applies the process directly to price rather than to a smoothed RSI.
First, a smooth average price range is calculated for the basis of the filter and multiplied by a specified amount.
Next, the filter is calculated by gating price movements that do not exceed the specified range.
Lastly the target ranges are plotted to display the prices that will trigger filter movement.
Custom bar colors are included. The color scheme is based on the filtered price trend.
Jurik Moving AverageThis indicator was originally developed by Mark Jurik.
NOTE: If Mr. Jurik ask me to remove this indicator from public access then I will do it.
Adaptive Least SquaresAn adaptive filtering technique allowing permanent re-evaluation of the filter parameters according to price volatility. The construction of this filter is based on the formula of moving ordinary least squares or lsma , the period parameter is estimated by dividing the true range with its highest. The filter will react faster during high volatility periods and slower during low volatility ones.
High smooth parameter will create smoother results, values inferior to 3 are recommended.
You can easily replace the parameter estimation method as long as the one used fluctuate in a range of , for example you can use the efficiency ratio
ER = abs(change(close,length))/sum(abs(change(close)),length)
Or the Fractal Dimension Index , in fact any values will work as long as they are rescaled (stoch(value,value,value,length)/100)
For any suggestions/questions feel free to send me a message :)
Ehlers Smoothed Adaptive MomentumEhlers Smoothed Adaptive Momentum script.
This indicator was developed and described by John F. Ehlers in his book "Cybernetic Analysis for Stocks and Futures" (2004, Chapter 12: Adapting to the Trend).