MA_Cross-over_Alerts_v1_1





//+------------------------------------------------------------------+
//|                                     EMA_Cross-over_Alerts_v1.mq4 |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                         EMA-Crossover_Signal.mq4 |
//|                                                                  |
//+------------------------------------------------------------------+
//+-------------------------------------------------------------------+
//|             v1_1 edited by tcl (http://sharingforex.blogspot.com  |
//|just make it as a universal MA crossing alert with Shift parameter |
//+-------------------------------------------------------------------+
/*
  +------------------------------------------------------------------+
  | Allows you to enter two ema periods and it will then show you at |
  | Which point they crossed over. It is more usful on the shorter   |
  | periods that get obscured by the bars / candlesticks and when    |
  | the zoom level is out. Also allows you then to remove the emas   |
  | from the chart.              
  +------------------------------------------------------------------+
*/   
//MODE_SMA 0 Simple moving average, 
//MODE_EMA 1 Exponential moving average, 
//MODE_SMMA 2 Smoothed moving average, 
//MODE_LWMA 3 Linear weighted moving average. 

//PRICE_CLOSE 0 Close price. 
//PRICE_OPEN 1 Open price. 
//PRICE_HIGH 2 High price. 
//PRICE_LOW 3 Low price. 
//PRICE_MEDIAN 4 Median price, (high+low)/2. 
//PRICE_TYPICAL 5 Typical price, (high+low+close)/3. 
//PRICE_WEIGHTED 6 Weighted close price, (high+low+close+close)/4. 

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 Red

double CrossUp[];
double CrossDown[];
int CurrentTrend = 0;
int starttime = 0;

extern string MA_MODE = "0=Simple, 1=Exponential, 2=Smoothed, 3= Linear Weighted"; //add by tcl - just for user information
extern string MA_PRICE1 = "0=Close, 1=Open, 2=High, 3=Low, 4=Median (high+low)/2"; //add by tcl - just for user information
extern string MA_PRICE2 = "5=Typical (high+low+close)/3, 6=Weighted Close (high+low+close+close)/4"; //add by tcl - just for user information
extern string note1 = "--- Faster MA Parameter ---"; //add by tcl - just for user information
//extern int FasterEMA = 5;
extern int FasterMA = 5; //edited by tcl
extern int FasterMA_MODE = 3;
extern int FasterMA_PRICE = 0;
extern int FasterMA_Shift = 0; //add by tcl

extern string note2 = "--- Faster MA Parameter ---"; //add by tcl - just for user information
//extern int SlowerEMA = 13;
extern int SlowerMA = 13; //edited by tcl
extern int SlowerMA_MODE = 3;
extern int SlowerMA_PRICE = 0;
extern int SlowerMA_Shift = 0; //add by tcl

extern string note3 = "--- Crossing Symbol Parameter ---"; //add by tcl - just for user information
//extern int Arrow_Symbol_UP = 108;
extern int Arrow_Symbol_UP = 233; //edited by tcl - make it an arrow as default crossing symbol
//extern int Arrow_Symbol_DN = 108;
extern int Arrow_Symbol_DN = 234; //edited by tcl - make it an arrow as default crossing symbol
extern int Arrow_Size      = 2;
extern int Show_Alert = 1;
extern int Play_Sound = 1;
extern int Send_Mail = 0;
extern string SoundFilename = "alert.wav";


int init()
  {
   SetIndexStyle(0, DRAW_ARROW,0,Arrow_Size);
   SetIndexArrow(0, Arrow_Symbol_UP);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW,0,Arrow_Size);
   SetIndexArrow(1, Arrow_Symbol_DN);
   SetIndexBuffer(1, CrossDown);
   starttime = TimeLocal();
   SetIndexLabel(0,"UP Signal");
   SetIndexLabel(1,"DN Signal");
   IndicatorShortName("EMA X Alerts");
   
   return(0);
  }


int deinit()
  {
   return(0);
  }


int start() {
   int limit, i, counter, loop;
   double fasterMAnow, slowerMAnow, fasterMAprevious, slowerMAprevious, fasterMAafter, slowerMAafter;
   double Range, AvgRange;
   int counted_bars=IndicatorCounted();

   //---- check for possible errors
   if(counted_bars<0) return(-1);

   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;

   loop = 0;
   for(i = 0; i <= limit; i++) {
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++)
      {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;
       
      fasterMAnow = iMA(NULL, 0, FasterMA, FasterMA_Shift, FasterMA_MODE, FasterMA_PRICE, i);
      fasterMAprevious = iMA(NULL, 0, FasterMA, FasterMA_Shift, FasterMA_MODE, FasterMA_PRICE, i+1);
      fasterMAafter = iMA(NULL, 0, FasterMA, FasterMA_Shift, FasterMA_MODE, FasterMA_PRICE, i-1);

      slowerMAnow = iMA(NULL, 0, SlowerMA, SlowerMA_Shift, SlowerMA_MODE, SlowerMA_PRICE, i);
      slowerMAprevious = iMA(NULL, 0, SlowerMA, SlowerMA_Shift, SlowerMA_MODE, SlowerMA_PRICE, i+1);
      slowerMAafter = iMA(NULL, 0, SlowerMA, SlowerMA_Shift, SlowerMA_MODE, SlowerMA_PRICE, i-1);
      
      if ((fasterMAnow > slowerMAnow) && (fasterMAprevious < slowerMAprevious) && (fasterMAafter > slowerMAafter)) {
         CrossUp[i] = Low[i] - Range*0.5;

         if ((loop == 0) && (CurrentTrend != 1) && (TimeLocal() - starttime >= 10))  {
            if (Show_Alert == 1)  {
               Alert("Cross Up on " + Symbol() + " " + Period() + "min " + FasterMA + "/" + SlowerMA + " EMA");
               }
            if (Play_Sound == 1)  {
               PlaySound(SoundFilename);
               }
            if (Send_Mail == 1)  {
               SendMail("Cross Up on " + Symbol() + " " + Period() + "min " + FasterMA + "/" + SlowerMA + " EMA", "");
               }
               
            CurrentTrend = 1;
            }

         if (loop == 0)  {
            loop = 1;
            }
      }
      else if ((fasterMAnow < slowerMAnow) && (fasterMAprevious > slowerMAprevious) && (fasterMAafter < slowerMAafter)) {
         CrossDown[i] = High[i] + Range*0.5;

         if ((loop == 0) && (CurrentTrend != -1) && (TimeLocal() - starttime >= 10))  {
            if (Show_Alert == 1)  {
               Alert("Cross Down on " + Symbol() + " " + Period() + "min " + FasterMA + "/" + SlowerMA + " EMA");
               }
            if (Play_Sound == 1)  {
               PlaySound(SoundFilename);
               }
            if (Send_Mail == 1)  {
               SendMail("Cross Down on " + Symbol() + " " + Period() + "min " + FasterMA + "/" + SlowerMA + " EMA", "");
               }
               
            CurrentTrend = -1;
            }

         if (loop == 0)  {
            loop = 1;
            }
       }
   }
   return(0);
}





Sample





Analysis



Market Information Used:

Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar


Indicator Curves created:

Implements a curve of type DRAW_ARROW


Indicators Used:

Moving average indicator


Custom Indicators Used:

Order Management characteristics:

Other Features:

It issuies visual alerts to the screen
It plays sound alerts
It sends emails