MAMA_FAMA





//+------------------------------------------------------------------+
//|                                                    MAMA_FAMA.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.ru/"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue

extern double    FastLimit=0.5;
extern double    SlowLimit=0.05;

//---- buffers
double MAMA[];
double FAMA[];
double SmoothPeriod[];
double Phase[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(4);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,MAMA);
   SetIndexLabel(0,"MAMA");
   
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,FAMA);
   SetIndexLabel(1,"FAMA");

   SetIndexBuffer(2,SmoothPeriod);
   SetIndexBuffer(3,Phase);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }

//+------------------------------------------------------------------+
//|  âû÷èñëèòü ìåäèàíó äëÿ áàðà ñ èíäåêñîì index                     |
//+------------------------------------------------------------------+
double Price(int index)
   {
   double res;
//----
   res=(High[index]+Low[index])/2.0;
//----
   return(res);   
   }

//+------------------------------------------------------------------+
//|  âû÷èñëèòü Smooth äëÿ áàðà ñ  èíäåêñîì i                         |
//+------------------------------------------------------------------+
double Smooth(int i)
   {
   double res;
//----
   res=(4*Price(i)+3*Price(i+1)+2*Price(i+2)+Price(i+3))/10.0;   
//----
   return(res);   
   }

//+------------------------------------------------------------------+
//|  âûñèëèòü Detrender æäÿ äàííîãî áàðà ñ çàäàííûì                  |
//+------------------------------------------------------------------+
double Detrender(int i, double ThatPer)
   {
   double res;
//----
   res=(0.0962*Smooth(i)+0.5769*Smooth(i+2)-0.5769*Smooth(i+4)-0.0962*Smooth(i+6))*(0.075*ThatPer+0.54);
//----
   return(res);   
   }
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int i,limit,counted_bars=IndicatorCounted();
   double periodD,prev_period,DeltaPhase,I1,Q1,thatPeriod;
   double alpha;
//----
   if (counted_bars==0) limit=Bars-27;
   if (counted_bars>0) limit=Bars-counted_bars;

   for (i=limit;i>=0;i--)
      {
      periodD=iCustom(NULL,0,"MAMA_Slave2",7,i);
      prev_period=iCustom(NULL,0,"MAMA_Slave2",7,i+1);
      thatPeriod=prev_period;
      Q1=iCustom(NULL,0,"MAMA_Slave2",6,i);
      I1=Detrender(i,thatPeriod);
      SmoothPeriod[i]=0.33*periodD+0.67*prev_period;
      if (I1!=0) Phase[i]=360*MathArctan(Q1/I1)/2*3.1415;
      DeltaPhase=Phase[i+1]-Phase[i];
      if (DeltaPhase<1) DeltaPhase=1;
      alpha=FastLimit/DeltaPhase;
      if (alpha<SlowLimit)  alpha=SlowLimit;
      MAMA[i]=alpha*Price(i)+(1-alpha)*MAMA[i+1];
      FAMA[i]=0.5*alpha*MAMA[i]+(1-0.5*alpha)*FAMA[i+1];
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar


Indicator Curves created:

Implements a curve of type DRAW_LINE


Indicators Used:




Custom Indicators Used:
MAMA_Slave2

Order Management characteristics:

Other Features: