TradingView
LazyBear
24 de May. de 2015 16:41

Ehlers MESA Adaptive Moving Average [LazyBear] 

Euro Fx/U.S. DollarFXCM

Descripción

Another one to add to Ehlers collection.

The MESA Adaptive Moving Average (MAMA) adapts to price movement based on the rate of change of phase as measured by the Hilbert Transform Discriminator. This method features a fast attack average and a slow decay average so that composite average rapidly ratchets behind price changes and holds the average value until the next ratchet occurs. Consider FAMA (Following AMA) as the signal.

Here are some of the options:

Fill MAMA/FAMA region (ribbon mode):


Mark Crossovers:


The above options (along with the bar colors) allow this to be used as a standalone system.

BTW, John Ehlers calls MAMA, "Mother of all Adaptive Moving Averages", lemme know what you think :)

More info:
- MESA Adaptive Moving Average, Stocks and Commodities Magazine, August 2001
- MAMA: mesasoftware.com/papers/MAMA.pdf

List of my public indicators: bit.ly/1LQaPK8
List of my app-store indicators: blog.tradingview.com/?p=970

Comentarios
ekoronin
I admire LazyBear and his work a lot, he is one of the inspiring person that got me coding indicators for TV for my own use as well.
Unfortunately in the case of MESA - this indicator is simply incorrect and does not work as expected - sadly.
I coded quite a number of indis by now from Ehlers original presentations and books, and at first I could not quite grasp why LB MESA doe not look like anything in Ehlers presentations. You can check how it should look in Ehlers presentation here:
ekoronin
(continued...)
mesasoftware.com/papers/MAMA.pdf

The stringently examining LazyBear's code I figured where the problem - it is actually in the two crucial parts of calculating the period and phase value.
The issue is that TV uses radians in trigonometric functions, whereas Ehlres formula refers to degrees - and the conversion is required for the formula to work properly.

Period, line 21 must

ekoronin
(for weird reasons paste operation sometimes posts my comment :) )

wrong:
p1 = iff(im!=0 and re!=0, 360/atan(im/re), nz(p[1]))

right:
p1 = iff(im!=0 and re!=0, 2*pi/atan(im/re), nz(p[1])), where pi = 3.14.5926

Phase, line 30
wrong:
phase = atan(q1 / i1)

right:
phase = 180/pi * atan(q1 / i1)


Until these corrections are made - the alpha value for MAM on line 34 is always bigger than fl=0.5, and as a result it never changes in the later calculation of the EMA. This MESA simply does not adapt to price changes. The alpha value stays constant 0.5 resulting in plotting the EMA(3) basically all the time. And the FAMA becomes EMA(7) of MAMA.

I believe I spotted similar coding issue in some other Ehlers based indicators, I can't unfortunately recall anymore which ones.

But apart from that I can only wish LazyBear to continue his great work for the community, big respect!

And this is how my version of MESA looks like
ekoronin
ekoronin
I chose this chart from may 2015 to replicate the original chart in the first LazyBear's post for comparison.
The choppiness of MESA is the confirmation of its adaptive nature. On fast price advances, it quickly slides along, whereas in the congested areas it flattens on retracements, because the alpha decreases and the EMA period increases.
Hope this brings big profits to everybody, all the best!
ekoronin
P.S.
Final correction:
>>where pi = 3.14.5926

pi = 3.1415926 indeed.
fede2.0
Hi! I would like to see your version of the MESA as you commented on LazyBear description of his own version. Could you publish it?
I can't code the corrections you made, error message...
Thank a lot for your contribution!!!
ekoronin
I am not publishing yet as I need to bring my scripts to a common standard, but i'm guessing you have forgot to define the pi variable. It would be good if you post the actual error.

Once again:
Add between line 10 and 11:
pi = 3.1415926

Change line 21 (old count before you added pi)
ekoronin
line 21:
p1 = iff(im!=0 and re!=0, 2*pi/atan(im/re), nz(p))

line 30 (old count again):
phase = 180/pi * atan(q1 / i1)

that should be all.

And I think I've finally figured out what causes earlier submission of my messages = if I paste a piece of code that has an invisible end-of-line character (cr/lf), the form treats it as ENTER button and submits the message. maybe this his something TradingView team can fix?
fede2.0
Thank you ekoronin, I made the modifictions but I still have an error, perhaps it is a little long to post but I publish a copy version of the indicator with the modifications as:
EHLERS MESA ADAPTIVE MOVING AVERAGE [LAZYBEAR] by Lazybear copy.
I don't know where my error is
Más