Navigation:Home > Content >

schaff_Plot_dcec_alerts.mq4

Time: 2016-10-03 | Download file:schaff_Plot_dcec_alerts.mq4

//+------------------------------------------------------------------+
//|                                                         Plot.mq4 |
//|                                                           mladen |
//+------------------------------------------------------------------+
//2009fxtsd mod extern colors rg colorscheme



#property copyright "mladen"
#property link      "mladenfx@gmail.com"

#property indicator_separate_window
#property indicator_buffers    3
#property indicator_color1     Red
#property indicator_color2     Lime
#property indicator_color3     Lime
#property indicator_width1     2
#property indicator_width2     2
#property indicator_width3     2
#property indicator_level1     15
#property indicator_level2     85
#property indicator_levelcolor Blue
//
//
//
//
//

extern string _                = "parameters";
extern int    STCPeriod        = 10;
extern int    FastMAPeriod     = 23;
extern int    SlowMAPeriod     = 50;

extern string note             = "turn on Alert = true; turn off = false";
extern bool   alertsOn         = true;
extern bool   alertsOnCurrent  = true;
extern bool   alertsMessage    = true;
extern bool   alertsSound      = true;
extern bool   alertsEmail      = false;
extern string soundfile        = "alert2.wav";

//
//
//
//
//

double stcBuffer[];
double stcBufferUA[];
double stcBufferUB[];
double macdBuffer[];
double fastKBuffer[];
double fastDBuffer[];
double fastKKBuffer[];
double trend[];

//
//
//
//
//

int init()
{
   
      IndicatorBuffers(8);
            SetIndexBuffer(0,stcBuffer);
            SetIndexBuffer(1,stcBufferUA);
            SetIndexBuffer(2,stcBufferUB);
            SetIndexBuffer(3,macdBuffer);
            SetIndexBuffer(4,fastKBuffer);
            SetIndexBuffer(5,fastDBuffer);
            SetIndexBuffer(6,fastKKBuffer);
            SetIndexBuffer(7,trend);
            
      IndicatorShortName("schaff");
   
   return(0);
}  

//
//
//
//
//

int deinit() { return(0); }

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

int start()
{
   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);
           if (trend[limit] == 1) ClearPoint(limit,stcBufferUA,stcBufferUB);
         
   //
   //
   //
   //
   //
           
      for(i = limit; i >= 0; i--)
      {
         macdBuffer[i] = iMA(NULL,0,FastMAPeriod,0,MODE_EMA,PRICE_CLOSE,i)-
                         iMA(NULL,0,SlowMAPeriod,0,MODE_EMA,PRICE_CLOSE,i);

         //
         //
         //
         //
         //
         
         double lowMacd  = minValue(macdBuffer,i);
         double highMacd = maxValue(macdBuffer,i)-lowMacd;
            if (highMacd > 0)
                  fastKBuffer[i] = 100*((macdBuffer[i]-lowMacd)/highMacd);
            else  fastKBuffer[i] = fastKBuffer[i+1];
                  fastDBuffer[i] = fastDBuffer[i+1]+0.5*(fastKBuffer[i]-fastDBuffer[i+1]);
               
         //
         //
         //
         //
         //
                     
         double lowStoch  = minValue(fastDBuffer,i);
         double highStoch = maxValue(fastDBuffer,i)-lowStoch;
            if (highStoch > 0)
                  fastKKBuffer[i] = 100*((fastDBuffer[i]-lowStoch)/highStoch);
            else  fastKKBuffer[i] = fastKKBuffer[i+1];
                  stcBuffer[i]    = stcBuffer[i+1]+0.5*(fastKKBuffer[i]-stcBuffer[i+1]);
         //
         //
         //
         //
         //
                  
                        trend[i] = trend[i+1];
         if (stcBuffer[i] > stcBuffer[i+1]) trend[i] =  1;
         if (stcBuffer[i] < stcBuffer[i+1]) trend[i] = -1;
         if (trend[i] == 1) PlotPoint(i,stcBufferUA,stcBufferUB,stcBuffer);
         }
         
         //
         //
         //
         //
         //
         
         if (alertsOn)
      {
      if (alertsOnCurrent)
           int whichBar = 0;
      else     whichBar = 1;

         //
         //
         //
         //
         //
         
         if (trend[whichBar] != trend[whichBar+1])
         if (trend[whichBar] == 1)
               doAlert("uptrend");
         else  doAlert("downtrend");       
   }
   
   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)," schaff ",doWhat);
             if (alertsMessage) Alert(message);
             if (alertsEmail)   SendMail(StringConcatenate(Symbol()," schaff "),message);
             if (alertsSound)   PlaySound(soundfile);
      }
}
   
//
//
//
//
//

double minValue(double& array[],int shift)
{
   double minValue = array[shift];
            for (int i=1; i        

Recommend