//+------------------------------------------------------------------+ //| TrendMACD v5.mq4 | //|Analyzing MACD histogram by the last three bars Genkov | //| for both trading and backtesting genkov@bk.ru | //+------------------------------------------------------------------+ #property copyright "Genkov" #property link "genkov@bk.ru" //if we comment on the string below, //no properties window will be displayed #property show_inputs extern int a = 1; // here you can set any initial bar to research //extern int period = 1; // minute //extern int period = 5; // 5 minutes //extern int period = 15; // 15 minutes //extern int period = 30; extern int period = 60; // comment on the timeframe you need //extern int period = 240; //extern int period = 1440; //extern int period = 10080; //extern int period = 43200; //+------------------------------------------------------------------+ int start() { // to disable Alerts, you need: int Message = 0;" int Message = 1; // int start=GetTickCount();//this is for counting the script operation time int b,c; b=a+1; c=b+1; //---- double Macd_h1_a= iMACD(NULL,period,12,26,9,PRICE_CLOSE,MODE_MAIN,a); double Macd_h1_b= iMACD(NULL,period,12,26,9,PRICE_CLOSE,MODE_MAIN,b); double Macd_h1_c= iMACD(NULL,period,12,26,9,PRICE_CLOSE,MODE_MAIN,c); // to make the calculation control visual, look at // these results, having enabled the 'Print' operator. // Print(" Macd_h1_c= ",Macd_h1_c*10," Macd_h1_b*10= ", // Macd_h1_b*10," Macd_h1_a= ",Macd_h1_a*10); if ( Message == 1 ) { // ----------------------for MACD below the axis-------------------------1--& if(Macd_h1_c<0.0&&Macd_h1_a<0.0&&Macd_h1_a<0.0) { //increment of bar "0" as related to the first one double r1=MathAbs(MathAbs(Macd_h1_a)-MathAbs(Macd_h1_b)); //increment of bar "1" as related to bar "2" double r2=MathAbs(MathAbs(Macd_h1_b)-MathAbs(Macd_h1_c)); // -- MACD is at the bottom - the trend is moving down if(Macd_h1_c>Macd_h1_b&&Macd_h1_b>Macd_h1_a) { if(r1>r2) { Alert("On ",a," bar, MACD<0 = ",Macd_h1_a, " The trend is moving down \\\'with acceleration"); } if(r1r2) { Alert("On ",a," bar, MACD<0 =",Macd_h1_a, " The trend is moving up //''with acceleration"); } if(r1Macd_h1_a) { if(r1>r2) { Alert("On ",a," bar, MACD<0 = ",Macd_h1_a, " The trend is turning down /\\'with acceleration"); } if(r1Macd_h1_b&&Macd_h1_br2) { Alert("On ",a," bar, MACD<0 = ",Macd_h1_a, " The trend is turning up //''with acceleration"); } if(r10.0 && Macd_h1_b>0.0 && Macd_h1_a>0.0) { { r1=MathAbs(MathAbs(Macd_h1_a)-MathAbs(Macd_h1_b)); r2=MathAbs(MathAbs(Macd_h1_c)-MathAbs(Macd_h1_b)); // MACD is above the axis - The trend is moving up if(Macd_h1_cr2)) { Alert("On ",a," bar, MACD >0 = ",Macd_h1_a, " The trend is moving up //''with acceleration"); } if(Macd_h1_c'0'= ",Macd_h1_a, " The trend is moving up /^with deceleration"); } if(Macd_h1_c'0' = ",Macd_h1_a, " The trend is moving up uniformly accelerated"); } } } // MACD is above the axis - The trend is moving down if(Macd_h1_c>Macd_h1_b&&Macd_h1_b>Macd_h1_a) { if((r1==r2)||MathAbs(r1-r2)<0.000015) { Alert("On ",a," bar, MACD > 0 = ",Macd_h1_a, " The trend is moving down uniformly accelerated"); } if(r1>r2) { Alert("On ",a," bar, MACD > 0 = ",Macd_h1_a, " The trend is moving down \\\'with acceleration"); } if(r1 0 = ",Macd_h1_a, " The trend is moving down \\^with deceleration"); } } // MACD is above the axis - The trend is turning down if(Macd_h1_cMacd_h1_a) { if(r1>r2) { Alert("On ",a," bar, MACD > 0 = ",Macd_h1_b, " The trend is turning down \\' with acceleration"); } if(r1 0 = ",Macd_h1_b," The trend ", " is turning down \\^ with deceleration"); } } // MACD is above the axis - The trend is turning up if(Macd_h1_c>Macd_h1_b&&Macd_h1_br2) { Alert("On ",a," bar, MACD > 0 ",Macd_h1_b," The trend", " is turning up //'' with acceleration"); } if(r1 0 ",Macd_h1_b," The trend", " is turning up //'' with deceleration"); } } if(MathAbs(MathAbs(Macd_h1_a)-MathAbs(Macd_h1_b))<0.0002 && MathAbs(MathAbs(Macd_h1_b)-MathAbs(Macd_h1_c))<0.0002) { Alert("On ",a," bar,it is Flat! ranging within: ",Macd_h1_c, " ",Macd_h1_b," ",Macd_h1_a); } } // ------------to cross the axis from bottom to top------------------3--& if(Macd_h1_c<0.0 && Macd_h1_b<0.0 && Macd_h1_a>0&& // c<0 b<0 Macd_h1_cMathAbs(r2)) { Alert("On ",a," bar, The trend is crossing the axis from bottom to top //'' with acceleration "); } if(MathAbs(r1)0.0 && Macd_h1_a>0&& // b>0 a>0 Macd_h1_cMathAbs(r2)) { Alert("On ",a," bar, The trend is crossing the axis from bottom to top //''with acceleration"); } if(MathAbs(r1)0 && Macd_h1_b>0 && Macd_h1_a<0&& // c>0 b>0 Macd_h1_c>Macd_h1_b&&Macd_h1_b>Macd_h1_a) { r1=MathAbs(Macd_h1_a)+MathAbs(Macd_h1_b); r2=MathAbs(Macd_h1_c)-MathAbs(Macd_h1_b); //-- if(MathAbs(r1)>MathAbs(r2)) { Alert("On ",a," bar, The trend is crossing the axis from top to bottom \\\' with acceleration"); } //-- if(MathAbs(r1)0 && Macd_h1_b<0 && Macd_h1_a<0&& // b<0 a<0 Macd_h1_c>Macd_h1_b&&Macd_h1_b>Macd_h1_a) { r1=MathAbs(Macd_h1_a)-MathAbs(Macd_h1_b); r2=MathAbs(Macd_h1_c)+MathAbs(Macd_h1_b); //-- if(MathAbs(r1)>MathAbs(r2)) { Alert("On ",a," bar, The trend is crossing the axis from top to bottom \\\' with acceleration"); } //-- if(MathAbs(r1)0&&Macd_h1_b==0&&Macd_h1_a<0&& Macd_h1_c>Macd_h1_b&&Macd_h1_b>Macd_h1_a) { r1=MathAbs(Macd_h1_a); r2=MathAbs(Macd_h1_c); if(MathAbs(r1)>MathAbs(r2)) { Alert("On ",a," bar, The trend is crossing the axis from top to bottom \\\' with acceleration" ); } if(MathAbs(r1)=0 && Macd_h1_a<0) { { r1=MathAbs(MathAbs(Macd_h1_a)-MathAbs(Macd_h1_b)); r2=MathAbs(MathAbs(Macd_h1_c)-MathAbs(Macd_h1_b)); if(r1==r2) { Alert("On ",a," bar, The trend above the axis is turning down uniformly accelerated"); } if(r1>r2) { Alert("On ",a," bar, The trend above the axis is turning down with acceleration!"); } if(r10 && Macd_h1_b<=0 && Macd_h1_a>0) { if(r1==r2) { Alert("On ",a," bar, The trend above the axis is turning up uniformly accelerated"); } if(r1>r2) { Alert("On ",a," bar, The trend above the axis is turning up with acceleration!"); } if(r1