//+------------------------------------------------------------------+ //| MAMA_Optim.mq5 | //| MQL5 Code: Copyright © 2010, Nikolay Kositsin | //| Khabarovsk, farria@mail.redcom.ru | //+------------------------------------------------------------------+ //---- author of the indicator #property copyright "Copyright © 2010, Nikolay Kositsin" #property link "farria@mail.redcom.ru" //---- indicator version number #property version "1.00" //---- drawing the indicator in the main window #property indicator_chart_window //----two buffers are used for calculation and drawing the indicator #property indicator_buffers 2 //---- two plots are used #property indicator_plots 2 //+----------------------------------------------+ //| FAMA indicator drawing parameters | //+----------------------------------------------+ //---- drawing indicator 1 as a line #property indicator_type1 DRAW_LINE //---- lime color is used as the color of a bullish candlestick #property indicator_color1 Lime //---- line of the indicator 1 is a solid curve #property indicator_style1 STYLE_SOLID //---- thickness of line of the indicator 1 is equal to 1 #property indicator_width1 1 //---- bullish indicator label display #property indicator_label1 "MAMA" //+----------------------------------------------+ //| MAMA indicator drawing parameters | //+----------------------------------------------+ //---- drawing indicator 2 as a line #property indicator_type2 DRAW_LINE //---- red color is used as the color of the bearish indicator line #property indicator_color2 Red //---- line of the indicator 2 is a solid curve #property indicator_style2 STYLE_SOLID //---- thickness of line of the indicator 2 is equal to 1 #property indicator_width2 1 //---- bearish indicator label display #property indicator_label2 "FAMA" //+----------------------------------------------+ //| Input parameters of the indicator | //+----------------------------------------------+ extern double FastLimit = 0.5; extern double SlowLimit = 0.05; //+----------------------------------------------+ //---- declaration of dynamic arrays that further //---- will be used as indicator buffers double MAMABuffer[]; double FAMABuffer[]; //---- Declaration of the integer variables for the start of data calculation int StartBar; //+------------------------------------------------------------------+ //| CountVelue() function | //+------------------------------------------------------------------+ double CountVelue(const int& CoArr[], double &Array1[],double &Array2[]) { //---- double Resalt= (0.0962*Array1[CoArr[0]] +0.5769*Array1[CoArr[2]] -0.5769*Array1[CoArr[4]] -0.0962*Array1[CoArr[6]]) *(0.075*Array2[CoArr[1]]+0.54); //---- return(Resalt); } //+------------------------------------------------------------------+ //| SmoothVelue() function | //+------------------------------------------------------------------+ double SmoothVelue(const int& CoArr[], double &Array[]) { //---- return(0.2*Array[CoArr[0]] +0.8*Array[CoArr[1]]); } //+------------------------------------------------------------------+ //| recalculation of position of the newest element in the array | //+------------------------------------------------------------------+ void Recount_ArrayZeroPos ( int& CoArr[] // Return the current value of the price series by the link ) // Recount_ArrayZeroPos(count, Length) //+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+ { //---- int numb; static int count=1; count--; if (count < 0) count = 6; for(int iii=0; iii<7; iii++) { numb=iii+count; if(numb>6) numb-=7; CoArr[iii]=numb; } //---- } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- initialization of constants StartBar=7+1; //---- transformation of the MAMABuffer dynamic array into an indicator buffer SetIndexBuffer(0,MAMABuffer,INDICATOR_DATA); //--- creation of a label to be displayed in the Data Window PlotIndexSetString(0,PLOT_LABEL,"MAMA"); //---- shifting the start of drawing of the indicator PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,StartBar); //---- transformation of the FAMABuffer dynamic array into an indicator buffer SetIndexBuffer(1,FAMABuffer,INDICATOR_DATA); //--- creation of a label to be displayed in the Data Window PlotIndexSetString(1,PLOT_LABEL,"FAMA"); //---- shifting the start of drawing of the indicator PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,StartBar+1); //---- initializations of variable for indicator short name string shortname; StringConcatenate(shortname,"The MESA Adaptive Moving Average(",FastLimit,", ",SlowLimit,")"); //---- creating name for displaying in a separate sub-window and in a tooltip IndicatorSetString(INDICATOR_SHORTNAME,shortname); //---- determination of accuracy of displaying of the indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); //---- } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate( const int rates_total, // amount of history in bars at the current tick const int prev_calculated,// amount of history in bars at the previous tick const int begin, // number of beginning of reliable counting of bars const double &price[] // price array for calculation of the indicator ) { //---- checking the number of bars to be enough for the calculation if(rates_total1.50*period[Bar1]) period[Bar0]=1.50*period[Bar1]; if(period[Bar0]<0.67*period[Bar1]) period[Bar0]=0.67*period[Bar1]; if(period[Bar0]<6.00) period[Bar0]=6.00; if(period[Bar0]>50.0) period[Bar0]=50.0; //---- period[Bar0]=0.2*period[Bar0]+0.8*period[Bar1]; //---- if(I1[Bar0]!=0) Phase[Bar0]=57.27272987*MathArctan(Q1[Bar0]/I1[Bar0]); //---- DeltaPhase=Phase[Bar1]-Phase[Bar0]; if(DeltaPhase<1) DeltaPhase=1.0; //---- alpha=FastLimit/DeltaPhase; if(alpha