MAMA.mq4

楼主  收藏   举报   帖子创建时间:  2019-05-05 05:03 回复:0 关注量:605
EURUSDM30.png

  1. //+------------------------------------------------------------------+
  2. //|                                                #MAMA.mq4 |
  3. //|                                                                  |
  4. //|                                       http://forex.kbpauk.ru/    |
  5. //+------------------------------------------------------------------+

  6. #property link      "http://forex.kbpauk.ru/"

  7. #property indicator_chart_window
  8. #property indicator_buffers 2
  9. #property indicator_color1 Aqua
  10. #property indicator_color2 Chocolate

  11. //---- input parameters
  12. extern double FastLimit=0.5;
  13. extern double SlowLimit=0.05;

  14. //---- buffers
  15. double FABuffer[];
  16. double MABuffer[];

  17. //+------------------------------------------------------------------+
  18. //| Custom indicator initialization function                         |
  19. //+------------------------------------------------------------------+
  20. int init()
  21.   {
  22.    string short_name;
  23. //---- indicator line
  24.    SetIndexStyle(0,DRAW_LINE);
  25.    SetIndexStyle(1,DRAW_LINE);
  26.    SetIndexBuffer(0,FABuffer);
  27.    SetIndexBuffer(1,MABuffer);

  28. //---- name for DataWindow and indicator subwindow label
  29.    short_name="#MAMA";
  30.    IndicatorShortName(short_name);
  31.    SetIndexLabel(0,"#FAMA");
  32.    SetIndexLabel(1,"#MAMA");

  33. //----
  34.    SetIndexDrawBegin(0,50);
  35.    SetIndexDrawBegin(1,50);

  36. //----
  37.    return(0);
  38.   }
  39. //+------------------------------------------------------------------+
  40. //| #MAMA                                                            |
  41. //+------------------------------------------------------------------+
  42. int start()
  43.   {
  44.    int i,counted_bars=IndicatorCounted();


  45. double jI, jQ, DeltaPhase, alpha, ttime;
  46. double Price[5],Smooth[8],Detrender[8],Q1[8],I1[8],I2[3],Q2[3];
  47. double Re[3],Im[3],SmoothPeriod[3],Period_[3],Phase[3],MAMA[3],FAMA[3];
  48. //----
  49.    if(Bars<=5) return(0);

  50. //----
  51.    i=(Bars-counted_bars)+50;
  52.    while(i>=0)
  53.      {
  54. Price[1]=((High[i]+Low[i])/2); Price[2]=((High[i+1]+Low[i+1])/2);
  55. Price[3]=((High[i+2]+Low[i+2])/2); Price[4]=((High[i+3]+Low[i+3])/2);

  56. Smooth[1] = (4*Price[1] + 3*Price[2] + 2*Price[3] + Price[4]) / 10;
  57. Detrender[1] = (0.0962*Smooth[1] + 0.5769*Smooth[3] - 0.5769*Smooth[5] - 0.0962*Smooth[7])*(0.075*Period_[2] + 0.54);

  58. // {Compute InPhase and Quadrature components}
  59. Q1[1] = (0.0962*Detrender[1] + 0.5769*Detrender[3] - 0.5769*Detrender[5] - 0.0962*Detrender[7])*(0.075*Period_[2] + 0.54);
  60. I1[1] = Detrender[4];

  61. // {Advance the phase of I1 and Q1 by 90 degrees}
  62. jI = (0.0962*I1[1] + 0.5769*I1[3] - 0.5769*I1[5] - 0.0962*I1[7])*(0.075*Period_[2] + 0.54);
  63. jQ = (0.0962*Q1[1] + 0.5769*Q1[3] - 0.5769*Q1[5] - 0.0962*Q1[7])*(0.075*Period_[2] + 0.54);

  64. // {Phasor addition for 3 bar averaging)}
  65. I2[1] = I1[1] - jQ;
  66. Q2[1] = Q1[1] + jI;

  67. // {Smooth the I and Q components before applying the discriminator}
  68. I2[1] = 0.2*I2[1] + 0.8*I2[2];
  69. Q2[1] = 0.2*Q2[1] + 0.8*Q2[2];

  70. // {Homodyne Discriminator}
  71. Re[1] = I2[1]*I2[2] + Q2[1]*Q2[2];
  72. Im[1] = I2[1]*Q2[2] - Q2[1]*I2[2];
  73. Re[1] = 0.2*Re[1] + 0.8*Re[2];
  74. Im[1] = 0.2*Im[1] + 0.8*Im[2];
  75. if (Im[1]!=0 && Re[1]!=0) Period_ [1]= 360/MathArctan(Im[1]/Re[1]);
  76. if (Period_[1]>1.5*Period_[2]) Period_[1] = 1.5*Period_[2];
  77. if (Period_[1]<0.67*Period_[2])Period_[1] = 0.67*Period_[2];
  78. if (Period_[1]<6) Period_[1] = 6;
  79. if (Period_[1]>50) Period_[1] = 50;
  80. Period_[1] = 0.2*Period_[1] + 0.8*Period_[2];
  81. SmoothPeriod[1] =0.33*Period_[1] + 0.67*SmoothPeriod[2];

  82. if (I1[1] != 0) Phase[1] = (MathArctan(Q1[1] / I1[1]));
  83. DeltaPhase = Phase[2] - Phase[1];
  84. if (DeltaPhase < 1) DeltaPhase = 1;
  85. alpha = FastLimit / DeltaPhase;
  86. if (alpha < SlowLimit)  alpha = SlowLimit;
  87. MAMA[1] = alpha*Price[1] + (1 - alpha)*MAMA[2];
  88. FAMA[1] = 0.5*alpha*MAMA[1] + (1 - 0.5*alpha)*FAMA[2];


  89. FABuffer[i]=MAMA[1];
  90. MABuffer[i]=FAMA[1];


  91. Smooth[7]=Smooth[5];Smooth[6]=Smooth[5];Smooth[5]=Smooth[4];Smooth[4]=Smooth[3];Smooth[3]=Smooth[2];Smooth[2]=Smooth[1];
  92. Detrender[7]=Detrender[6];Detrender[6]=Detrender[5];Detrender[5]=Detrender[4];Detrender[4]=Detrender[3];Detrender[3]=Detrender[2];Detrender[2]=Detrender[1];
  93. Q1[7]=Q1[6];Q1[6]=Q1[5];Q1[5]=Q1[4];Q1[4]=Q1[3];Q1[3]=Q1[2];Q1[2]=Q1[1];
  94. I1[7]=I1[6];I1[6]=I1[5];I1[5]=I1[4];I1[4]=I1[3];I1[3]=I1[2];I1[2]=I1[1];
  95. Q2[2]=Q2[1];
  96. I2[2]=I2[1];
  97. Re[2]=Re[1];
  98. Im[2]=Im[1];
  99. SmoothPeriod[2]=SmoothPeriod[1];
  100. Phase[2]=Phase[1];
  101. Period_[2]=Period_[1];
  102. MAMA[2]=MAMA[1];
  103. FAMA[2]=FAMA[1];




  104. i--;
  105.      }
  106.    return(0);
  107.   }
  108. //+------------------------------------------------------------------+
打赏