Navigation:Home > Content >

TrendstrenghtEMA_alerts.mq4

Time: 2016-05-21 | Download file:TrendstrenghtEMA_alerts.mq4

//+------------------------------------------------------------------+ 
//|                                             TrendStrengthEMA.mq4 | 
//|                                                        Xaoc 2006 | 
//|                                             http://forex.xcd.ru/ | 
//|                                          modified by Braindancer |
//+------------------------------------------------------------------+ 
#property copyright "][aoc 2006" 
#property link      "http://forex.xcd.ru/" 


#property indicator_separate_window 
#property indicator_buffers 1 
#property indicator_color1 DarkOrange
#property indicator_width1 4
#property indicator_level1 0
#property indicator_levelcolor Violet



extern string _                = "alerts settings";
extern bool   alertsOn         = true;
extern bool   alertsOnCurrent  = true;
extern bool   alertsMessage    = true;
extern bool   alertsSound      = false;
extern bool   alertsEmail      = false;





double TS[];
double trend[];




int init() 
  { 
   IndicatorBuffers(2);  
   SetIndexBuffer(0,TS); SetIndexStyle(0, DRAW_HISTOGRAM); 
   SetIndexBuffer(1,trend); 
   
   IndicatorShortName(" TrendStrengthEMA "); 
   return(0); 
  } 

int deinit() {  return(0);  } 
  

   

int start() 
  { 
  
   double ma0, ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8, ma9, tmp; 
   int counted_bars=IndicatorCounted();
   int i,limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit = MathMin(Bars-counted_bars,Bars-1);
   
    for(i=limit; i>=0; i--)
   {
       tmp = iMA(NULL,0,11,0,MODE_EMA,PRICE_CLOSE,i);     
   ma1=tmp - iMA(NULL,0,5,0, MODE_EMA,PRICE_CLOSE,i); 
   ma2=tmp - iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,i); 
   ma3=tmp - iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,i); 
   ma4=tmp - iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,i);  
   ma5=tmp - iMA(NULL,0,25,0,MODE_EMA,PRICE_CLOSE,i);
   ma6=tmp - iMA(NULL,0,30,0,MODE_EMA,PRICE_CLOSE,i);
   ma7=tmp - iMA(NULL,0,40,0,MODE_EMA,PRICE_CLOSE,i);
         
         
   TS[i]=(ma1+ma2+ma3+ma4+ma5+ma6+ma7)/7;
   
   trend[i] = trend[i+1];
   if(TS[i] > 0 && TS[i+1] <=0) trend[i] =  1;  
   if(TS[i] < 0 && TS[i+1] >=0) trend[i] = -1;   
   } 
   if (alertsOn)
   {
      if (alertsOnCurrent)
           int whichBar = 0;
      else     whichBar = 1;

         //
         //
         //
         //
         //
         
         if (trend[whichBar] != trend[whichBar+1])
         if (trend[whichBar] == 1)
               doAlert("up");
         else  doAlert("down");       
   }

   //
   //
   //
   //
   //
      
   return(0);
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+  
//
//
//
//
//

void doAlert(string doWhat)
{
   static string   previousAlert="nothing";
   static datetime previousTime;
   string message;
   
      if (previousAlert != doWhat || previousTime != Time[0]) {
          previousAlert  = doWhat;
          previousTime   = Time[0];

          //
          //
          //
          //
          //

          message =  StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," Trendstrength trend changed to ",doWhat);
             if (alertsMessage) Alert(message);
             if (alertsEmail)   SendMail(StringConcatenate(Symbol(),"  Trendstrength "),message);
             if (alertsSound)   PlaySound("alert2.wav");
      }
}

         
 

Recommend