4 JMA Crossover Strategy (ps4)This is a PS4 update to my previous 4 JMA strategy that received many likes. In this and several recent strategies I use a simplified strategy setup, featuring trailing stops with very tiny increments. This is done intentionally in order to boost performance to the limit, so that to pinpoint that limit. Strategies with performance of about 90% or above are regarded as viable. Incorporating various overhead factors such as transaction costs, broker's spread, slippage, etc. at this stage creates too much 'noise' with the end result of losing the sight of the forest behind the trees.)) In practice, I disable the 'Use Strategy Setup' option and fine-tune parameters the way I want.
Tested security: EURUSD . Tested TF: 3m
JMA
Many Moving AveragesThis script allows you to add two moving averages to a chart, where the type of moving average can be chosen from a collection of 15 different moving average algorithms. Each moving average can also have different lengths and crossovers/unders can be displayed and alerted on.
The supported moving average types are:
Simple Moving Average ( SMA )
Exponential Moving Average ( EMA )
Double Exponential Moving Average ( DEMA )
Triple Exponential Moving Average ( TEMA )
Weighted Moving Average ( WMA )
Volume Weighted Moving Average ( VWMA )
Smoothed Moving Average ( SMMA )
Hull Moving Average ( HMA )
Least Square Moving Average/Linear Regression ( LSMA )
Arnaud Legoux Moving Average ( ALMA )
Jurik Moving Average ( JMA )
Volatility Adjusted Moving Average ( VAMA )
Fractal Adaptive Moving Average ( FRAMA )
Zero-Lag Exponential Moving Average ( ZLEMA )
Kauman Adaptive Moving Average ( KAMA )
Many of the moving average algorithms were taken from other peoples' scripts. I'd like to thank the authors for making their code available.
JayRogers
Alex Orekhov (everget)
Alex Orekhov (everget)
Joris Duyck (JD)
nemozny
Shizaru
KobySK
Jurik Research and Consulting for inventing the JMA.
Exponential Hull MA Oscillator PrototypeClamped EHMA Oscillator Prototype with 21/200 EHMA with additional JMA smoothing (Credit: @everget)
Note: This is an experiment - this is not a polished indicator
Dickinson Moving Average (DMA)Implementation of the "Dickinson Moving Average" from the r/algotrading post by Nathan Dickinson
Quoted from the author of the Dickinson Moving Average:
"I was experimenting with the “zero lag” code from John Ehlers and the Hull Moving Average and noticed that they seemed to respond in complementary ways when properly set up. With the right starting values, they blend together to make a moving average which responds with one (or maybe even half a bar) of lag. To my eye, it looks to be almost as good as the Jurik Moving Average."
Optional parameter input available to use Exponential Hull Moving Average (EHMA) instead of WMA for the Hull MA is available.
Acknowledgements/Credits:
Nathan Dickinson, Dickinson Moving Average
@RicardoSantos, Function for Hull Moving Average
Exponential Hull Moving Average sourced from:
// Raudys, Aistis & Lenčiauskas, Vaidotas & Malčius, Edmundas. (2013). Moving Averages for Financial Data Smoothing.
// Communications in Computer and Information Science. 403. 34-45. 10.1007/978-3-642-41947-8_4.
@Everget, Jurik Moving Average
General Filter Estimator-An Experiment on Estimating EverythingIntroduction
The last indicators i posted where about estimating the least squares moving average, the task of estimating a filter is a funny one because its always a challenge and it require to be really creative. After the last publication of the 1LC-LSMA , who estimate the lsma with 1 line of code and only 3 functions i felt like i could maybe make something more flexible and less complex with the ability to approximate any filter output. Its possible, but the methods to do so are not something that pinescript can do, we have to use another base for our estimation using coefficients, so i inspired myself from the alpha-beta filter and i started writing the code.
Calculation and The Estimation Coefficients
Simplicity is the key word, its also my signature style, if i want something good it should be simple enough, so my code look like that :
p = length/beta
a = close - nz(b ,close)
b = nz(b ,close) + a/p*gamma
3 line, 2 function, its a good start, we could put everything in one line of code but its easier to see it this way. length control the smoothing amount of the filter, for any filter f(Period) Period should be equal to length and f(Period) = p , it would be inconvenient to have to use a different length period than the one used in the filter we want to estimate (imagine our estimation with length = 50 estimating an ema with period = 100) , this is where the first coefficients beta will be useful, it will allow us to leave length as it is. In general beta will be greater than 1, the greater it will be the less lag the filter will have, this coefficient will be useful to estimate low lagging filters, gamma however is the coefficient who will estimate lagging filters, in general it will range around .
We can get loose easily with those coefficients estimation but i will leave a coefficients table in the code for estimating popular filters, and some comparison below.
Estimating a Simple Moving Average
Of course, the boxcar filter, the running mean, the simple moving average, its an easy filter to use and calculate.
For an SMA use the following coefficients :
beta = 2
gamma = 0.5
Our filter is in red and the moving average in white with both length at 50 (This goes for every comparison we will do)
Its a bit imprecise but its a simple moving average, not the most interesting thing to estimate.
Estimating an Exponential Moving Average
The ema is a great filter because its length times more computing efficient than a simple moving average. For the EMA use the following coefficients :
beta = 3
gamma = 0.4
N.B : The EMA is rougher than the SMA, so it filter less, this is why its faster and closer to the price
Estimating The Hull Moving Average
Its a good filter for technical analysis with tons of use, lets try to estimate it ! For the HMA use the following coefficients :
beta = 4
gamma = 0.85
Looks ok, of course if you find better coefficients i will test them and actualize the coefficient table, i will also put a thank message.
Estimating a LSMA
Of course i was gonna estimate it, but this time this estimation does not have anything a lsma have, no moving average, no standard deviation, no correlation coefficient, lets do it.
For the LSMA use the following coefficients :
beta = 3.5
gamma = 0.9
Its far from being the best estimation, but its more efficient than any other i previously made.
Estimating the Quadratic Least Square Moving Average
I doubted about this one but it can be approximated as well. For the QLSMA use the following coefficients :
beta = 5.25
gamma = 1
Another ok estimate, the estimate filter a bit more than needed but its ok.
Jurik Moving Average
Its far from being a filter that i like and its a bit old. For the comparison i will use the JMA provided by @everget described in this article : c.mql5.com
For the JMA use the following coefficients :
for phase = 0
beta = pow*2 (pow is a parameter in the Jma)
gamma = 0.5
Here length = 50, phase = 0, pow = 5 so beta = 10
Looks pretty good considering the fact that the Jma use an adaptive architecture.
Discussion
I let you the task to judge if the estimation is good or not, my motivation was to estimate such filters using the less amount of calculations as possible, in itself i think that the code is quite elegant like all the codes of IIR filters (IIR Filters = Infinite Impulse Response : Filters using recursion) .
It could be possible to have a better estimate of the coefficients using optimization methods like the gradient descent. This is not feasible in pinescript but i could think about it using python or R.
Coefficients should be dependant of length but this would lead to a massive work, the variation of the estimation using fixed coefficients when using different length periods is just ok if we can allow some errors of precision.
I dont think it should be possible to estimate adaptive filter relying a lot on their adaptive parameter/smoothing constant except by making our coefficients adaptive (gamma could be)
So at the end ? What make a filter truly unique ? From my point of sight the architecture of a filter and the problem he is trying to solve is what make him unique rather than its output result. If you become a signal, hide yourself into noise, then look at the filters trying to find you, what a challenging game, this is why we need filters.
Conclusion
I wanted to give a simple filter estimator relying on two coefficients in order to estimate both lagging and low-lagging filters. I will try to give more precise estimate and update the indicator with new coefficients.
Thanks for reading !
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.
RSX FracticalityA little project I was working on to avoid studying for finals. Using LazyBear's RSX code for a smoother RSI, then taking the RSX of fib number lengths. Take the average of that, then the JMA of that from the same fib numbers. The average of that is then treated as the trend, take the average of the trend values from the main time frames, the script calls pretty far back so adding a W or M TF I think would throw the calculations off. Then I smoothed that value using the jma's to create the overall trend. I got the idea from Ehler's Empirical Mode Decomposition about identifying peaks and valleys and creating an average of that to create a range. The idea is that if the trend is above the Average Peak then it is a bull trend, less than the average valley it's a bear trend, in between it's ranging. It looks like it turned out alright, I'll be working on this idea of fractals a lot this summer to see if I can improve it or build something better off of the idea.