Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Help requested for MESA MAMA FAMA indicator function
Updated October 7, 2014
Top Posters
looks_one
Lamboo
with 6 posts (2 thanks)
looks_two
gpw797
with 5 posts (0 thanks)
looks_3
cbritton
with 4 posts (2 thanks)
looks_4
ABCTG
with 3 posts (4 thanks)
Best Posters
looks_one
ABCTG
with 1.3 thanks per post
looks_two
Big Mike
with 1 thanks per post
looks_3
cbritton
with 0.5 thanks per post
looks_4
Lamboo
with 0.3 thanks per post
trending_up
14,982 views
thumb_up
10 thanks given
group
5 followers
forum
21 posts
attach_file
0 attachments
Help requested for MESA MAMA FAMA indicator function
December 15th, 2010, 02:48 PM
Mesa, AZ
Posts: 55 since Oct 2010
I have been playing around with the MAMA FAMA indicator and want to try some strategy stuff but I don't have the programming skills to turn this into functions. Can somebody help with turning these into functions or point to place on the web for the functions? Code for indicators is below, thanks
Code
{Ehlers MAMA and FAMA indicator - coded by dn
//// From Cybernetic Analysis for Stocks and Futures}
Inputs: Price((H+L)/2), FastLimit(.5),SlowLimit(.05);
Vars: Smooth(0), Detrender(0),I1(0),Q1(0),jI(0),jQ(0),I2(0),Q2(0),Re(0),
Im(0), Period(0),SmoothPeriod(0),Phase(0),DeltaPhase(0),alpha(0),
MAMA(0),FAMA(0);
If CurrentBar > 5 then begin
Smooth = (4*Price + 3*Price[1] + 2*Price[2] + Price[3]) / 10;
Detrender = (.0962*Smooth + .5769*Smooth[2] - .5769*Smooth[4]
- .0962*Smooth[6])*(.075*Period[1] + .54);
{Compute InPhase and Quadrature components}
Q1 = (.0962*Detrender + .5769*Detrender[2] - .5769*Detrender[4]
- .0962*Detrender[6])*(.075*Period[1] + .54);
I1 = Detrender[3];
{Advance the phase of I1 and Q1 by 90 degrees}
jI = (.0962*I1 + .5769*I1[2] - .5769*I1[4]
- .0962*I1[6])*(.075*Period[1] + .54);
jQ = (.0962*Q1 + .5769*Q1[2] - .5769*Q1[4]
- .0962*Q1[6])*(.075*Period[1] + .54);
{Phasor addition for 3-bar averaging)}
I2 = I1 - jQ;
Q2 = Q1 + jI;
{Smooth the I and Q components before applying the discriminator}
I2 = .2*I2 + .8*I2[1];
Q2 = .2*Q2 + .8*Q2[1];
{Homodyne Discriminator}
Re = I2*I2[1] + Q2*Q2[1];
Im = I2*Q2[1] - Q2*I2[1];
Re = .2*Re + .8*Re[1];
Im = .2*Im + .8*Im[1];
If Im <> 0 and Re <> 0 then Period = 360/ArcTangent(Im/Re);
If Period > 1.5*Period[1] then Period = 1.5*Period[1];
If Period < .67*Period[1] then Period = .67*Period[1];
If Period < 6 then Period = 6;
If Period > 50 then Period = 50;
Period = .2*Period + .8*Period[1];
SmoothPeriod = .33*Period + .67*SmoothPeriod[1];
If I1 <> 0 then Phase = (ArcTangent(Q1 / I1));
DeltaPhase = Phase[1] - Phase;
If DeltaPhase < 1 then DeltaPhase = 1;
alpha = FastLimit / DeltaPhase;
If alpha < SlowLimit then alpha = SlowLimit;
If alpha > FastLimit then alpha = FastLimit;
MAMA = alpha*Price + (1 - alpha)*MAMA[1];
FAMA = .5*alpha*MAMA + (1 - .5*alpha)*FAMA[1];
Plot1(MAMA, "MAMA");
Plot2(FAMA, "FAMA");
End;
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
December 15th, 2010, 02:58 PM
Atlanta, Georgia
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256
Try this:
function:
Code
{Ehlers MAMA and FAMA indicator - coded by dn
//// From Cybernetic Analysis for Stocks and Futures}
Inputs: Price(NumericSeries), FastLimit(NumericSimple),SlowLimit(NumericSimple), MAMA(NumericRef), FAMA(NumericRef);
Vars: Smooth(0), Detrender(0),I1(0),Q1(0),jI(0),jQ(0),I2(0),Q2(0),Re(0),
Im(0), Period(0),SmoothPeriod(0),Phase(0),DeltaPhase(0),alpha(0),
_MAMA(0),_FAMA(0);
If CurrentBar > 5 then begin
Smooth = (4*Price + 3*Price[1] + 2*Price[2] + Price[3]) / 10;
Detrender = (.0962*Smooth + .5769*Smooth[2] - .5769*Smooth[4]
- .0962*Smooth[6])*(.075*Period[1] + .54);
{Compute InPhase and Quadrature components}
Q1 = (.0962*Detrender + .5769*Detrender[2] - .5769*Detrender[4]
- .0962*Detrender[6])*(.075*Period[1] + .54);
I1 = Detrender[3];
{Advance the phase of I1 and Q1 by 90 degrees}
jI = (.0962*I1 + .5769*I1[2] - .5769*I1[4]
- .0962*I1[6])*(.075*Period[1] + .54);
jQ = (.0962*Q1 + .5769*Q1[2] - .5769*Q1[4]
- .0962*Q1[6])*(.075*Period[1] + .54);
{Phasor addition for 3-bar averaging)}
I2 = I1 - jQ;
Q2 = Q1 + jI;
{Smooth the I and Q components before applying the discriminator}
I2 = .2*I2 + .8*I2[1];
Q2 = .2*Q2 + .8*Q2[1];
{Homodyne Discriminator}
Re = I2*I2[1] + Q2*Q2[1];
Im = I2*Q2[1] - Q2*I2[1];
Re = .2*Re + .8*Re[1];
Im = .2*Im + .8*Im[1];
If Im <> 0 and Re <> 0 then Period = 360/ArcTangent(Im/Re);
If Period > 1.5*Period[1] then Period = 1.5*Period[1];
If Period < .67*Period[1] then Period = .67*Period[1];
If Period < 6 then Period = 6;
If Period > 50 then Period = 50;
Period = .2*Period + .8*Period[1];
SmoothPeriod = .33*Period + .67*SmoothPeriod[1];
If I1 <> 0 then Phase = (ArcTangent(Q1 / I1));
DeltaPhase = Phase[1] - Phase;
If DeltaPhase < 1 then DeltaPhase = 1;
alpha = FastLimit / DeltaPhase;
If alpha < SlowLimit then alpha = SlowLimit;
If alpha > FastLimit then alpha = FastLimit;
_MAMA = alpha*Price + (1 - alpha)*_MAMA[1];
_FAMA = .5*alpha*_MAMA + (1 - .5*alpha)*_FAMA[1];
MAMA= _MAMA;
FAMA=_FAMA;
End;
MAMA_FAMA=0;
indicator:
Code
{Ehlers MAMA and FAMA indicator - coded by dn
//// From Cybernetic Analysis for Stocks and Futures}
Inputs: Price((H+L)/2), FastLimit(.5),SlowLimit(.05);
Vars: MAMA(0), FAMA(0);
value0 = MAMA_FAMA(price, fastlimit, slowlimit, MAMA, FAMA);
Plot1(MAMA, "MAMA");
Plot2(FAMA, "FAMA");
Regards,
-C
“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
December 15th, 2010, 03:21 PM
Mesa, AZ
Posts: 55 since Oct 2010
I got it to compile w/o the last line "MAMA_FAMA=0;"
I can compile as 2 different functions and call each up separately? Or is there a way to reference each indicator within the single function? Your help is much appreciated, thanks.
December 15th, 2010, 03:26 PM
Atlanta, Georgia
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256
gpw797
I got it to compile w/o the last line "MAMA_FAMA=0;"
I can compile as 2 different functions and call each up separately? Or is there a way to reference each indicator within the single function? Your help is much appreciated, thanks.
Really? It compiles for me without a problem. I'm using 8.8, update 6188.
Yes, you can split the function up. One to return FAMA and the other to return MAMA, but that's computationally more expensive, having to perform the same set of work twice. If that's not your concern, then go for it.
Regards,
-C
“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
December 15th, 2010, 03:32 PM
Mesa, AZ
Posts: 55 since Oct 2010
Opps.. I forgot to mention I am using Multicharts (sounds like you are using Tradestation by your version number). I will look at it some more tonight, thanks.
December 15th, 2010, 03:34 PM
Atlanta, Georgia
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256
gpw797
Opps.. I forgot to mention I am using
Multicharts (sounds like you are using Tradestation by your version number). I will look at it some more tonight, thanks.
And here I was thinking that there's no difference between the two easy language platforms
Good to know there are some differences.
Regards,
-C
“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
December 15th, 2010, 03:38 PM
Manta, Ecuador
Site Administrator Developer Swing Trader
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,475 since Jun 2009
Thanks Given: 33,251
Thanks Received: 101,679
gpw797
I got it to compile w/o the last line "MAMA_FAMA=0;"
I can compile as 2 different functions and call each up separately? Or is there a way to reference each indicator within the single function? Your help is much appreciated, thanks.
Make sure you named the function "MAMA_FAMA".
Mike
December 15th, 2010, 03:45 PM
Atlanta, Georgia
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256
Big Mike
Make sure you named the function "MAMA_FAMA".
Mike
Yes, an important point I left out
Regards,
-C
“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
December 15th, 2010, 05:35 PM
Mesa, AZ
Posts: 55 since Oct 2010
Changed name and got it to compile not excluding the last line. But not getting any signals generated from the following. What am I doing wrong? Thanks Sorry I am beginner at this stuff but trying to learn
Code
//First attempt at MAMA FAMA
Inputs:
Price((H+L)/2),
FastLimit(.5),
SlowLimit(.05),
contractsize (1);
Variables:
MAMA (0),
FAMA (0);
If FAMA > MAMA then Buy contractsize Contracts Next Bar At Market;
If FAMA < MAMA then Sell short contractsize Contracts Next Bar At Market;
Last Updated on October 7, 2014