NexusFi: Find Your Edge


Home Menu

 





Help requested for MESA MAMA FAMA indicator function


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one Lamboo with 6 posts (2 thanks)
    2. looks_two gpw797 with 5 posts (0 thanks)
    3. looks_3 cbritton with 4 posts (2 thanks)
    4. looks_4 ABCTG with 3 posts (4 thanks)
      Best Posters
    1. looks_one ABCTG with 1.3 thanks per post
    2. looks_two Big Mike with 1 thanks per post
    3. looks_3 cbritton with 0.5 thanks per post
    4. looks_4 Lamboo with 0.3 thanks per post
    1. trending_up 14,844 views
    2. thumb_up 10 thanks given
    3. group 5 followers
    1. forum 21 posts
    2. attach_file 0 attachments




 
Search this Thread

Help requested for MESA MAMA FAMA indicator function

  #1 (permalink)
 gpw797 
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;

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
Exit Strategy
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
Increase in trading performance by 75%
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
28 thanks
Tao te Trade: way of the WLD
24 thanks
Diary of a simple price action trader
21 thanks
My NQ Trading Journal
14 thanks
GFIs1 1 DAX trade per day journal
9 thanks
  #3 (permalink)
 
cbritton's Avatar
 cbritton 
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
Reply With Quote
Thanked by:
  #4 (permalink)
 gpw797 
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.

Reply With Quote
  #5 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256


gpw797 View Post
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
Reply With Quote
Thanked by:
  #6 (permalink)
 gpw797 
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.

Reply With Quote
  #7 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256


gpw797 View Post
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
Reply With Quote
  #8 (permalink)
 
Big Mike's Avatar
 Big Mike 
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,440 since Jun 2009
Thanks Given: 33,207
Thanks Received: 101,599


gpw797 View Post
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

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #9 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256


Big Mike View Post
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
Reply With Quote
  #10 (permalink)
 gpw797 
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;

Reply With Quote




Last Updated on October 7, 2014


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts