//+------------------------------------------------------------------+
//| This MQL is generated by Expert Advisor Builder                  |
//|                http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/ |
//|                                                                  |
//|  In no event will author be liable for any damages whatsoever.   |
//|                      Use at your own risk.                       |
//|                                                                  |
//+------------------- DO NOT REMOVE THIS HEADER --------------------+

#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Yellow
#property indicator_color2 DarkViolet
#property indicator_color3 Lime
#property indicator_color4 Red

extern int FastEMA = 13;
extern int SlowEMA = 21;
extern int RSIPeriod = 9;
extern bool Alerts = FALSE;
double uGaf[];
double uGag[];
double uGah[];
double uGai[];
int gUIA = 0;
int gUIB = 0;
double cLov = 0.0;
double cLova = 0.0;

datetime alertTimeOnce=0;

int init() {
   SetIndexStyle(0, DRAW_LINE,0,2);
     SetIndexBuffer(0, uGaf);
   SetIndexStyle(1, DRAW_LINE,0,2);
   SetIndexBuffer(1, uGag);
   SetIndexStyle(2, DRAW_ARROW);
   SetIndexArrow(2, 217);
   SetIndexBuffer(2, uGah);
   SetIndexEmptyValue(2, 0.0);
   SetIndexStyle(3, DRAW_ARROW);
   SetIndexArrow(3, 218);
   SetIndexBuffer(3, uGai);
   SetIndexEmptyValue(3, 0.0);
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   int indCount = IndicatorCounted();
   double reZL = 0;
   bool whistle = FALSE;
   double actPrice = 0;
   if (indCount < 0) return (-1);
   if (indCount > 0) indCount--;
   int barCount = Bars - indCount;
   for (int emaPOS = 0; emaPOS < barCount; emaPOS++) {
      uGaf[emaPOS] = iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, emaPOS);
      uGag[emaPOS] = iMA(NULL, 0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, emaPOS);
      reZL = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, emaPOS);
      cLov = uGaf[emaPOS] - uGag[emaPOS];
      Comment("pipdiffCurrent = " + cLov + " ");
      if (cLov > 0.0 && reZL > 50.0) gUIA = 1;
      else
         if (cLov < 0.0 && reZL < 50.0) gUIA = 2;
      if (gUIA == 1 && gUIB == 2) {
         uGai[emaPOS - 1] = High[emaPOS - 1] - 5.0 * Point;
         whistle = TRUE;
         actPrice = Ask;
      } else {
         if (gUIA == 2 && gUIB == 1) {
            uGah[emaPOS - 1] = Low[emaPOS - 1] - 5.0 * Point;
            whistle = TRUE;
            actPrice = Bid;
         }
      }
      gUIB = gUIA;
      cLova = cLov;
   }
   if (Alerts && whistle && alertTimeOnce!=Time[0]) {
      PlaySound("alert.wav");
      if (gUIB == 1) MessageBox("Entry point: buy at " + actPrice + "!!", "Entry Point", 0);
      else
         if (gUIB == 2) MessageBox("Entry point: sell at " + actPrice + "!!", "Entry Point", 0);
      whistle = FALSE;
      alertTimeOnce=Time[0];
   }
   return (0);
}