//+------------------------------------------------------------------+
//| 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 Blue
#property indicator_color2 Yellow
#property indicator_color3 Aqua
#property indicator_color4 Red

extern int FastEMA = 13;
extern int SlowEMA = 21;
extern int RSIPeriod = 9;
extern bool Alerts = TRUE;
double inine[];
double sine[];
double kline[];
double lima[];
int oraim = 0;
int oraimo = 0;
double dooze = 0.0;
double snooze = 0.0;

int init() {
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, inine);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, sine);
   SetIndexStyle(2, DRAW_ARROW);
   SetIndexArrow(2, 217);
   SetIndexBuffer(2, kline);
   SetIndexEmptyValue(2, 0.0);
   SetIndexStyle(3, DRAW_ARROW);
   SetIndexArrow(3, 218);
   SetIndexBuffer(3, lima);
   SetIndexEmptyValue(3, 0.0);
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   int mea = IndicatorCounted();
   double irsi = 0;
   bool nxet = FALSE;
   double price_20 = 0;
   if (mea < 0) return (-1);
   if (mea > 0) mea--;
   int olx = Bars - mea;
   for (int moov = 0; moov < olx; moov++) {
      inine[moov] = iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, moov);
      sine[moov] = iMA(NULL, 0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, moov);
      irsi = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, moov);
      dooze = inine[moov] - sine[moov];
      Comment("pipdiffCurrent = " + dooze + " ");
      if (dooze > 0.0 && irsi > 50.0) oraim = 1;
      else
         if (dooze < 0.0 && irsi < 50.0) oraim = 2;
      if (oraim == 1 && oraimo == 2) {
         lima[moov - 1] = High[moov - 1] - 5.0 * Point;
         nxet = TRUE;
         price_20 = Ask;
      } else {
         if (oraim == 2 && oraimo == 1) {
            kline[moov - 1] = Low[moov - 1] - 5.0 * Point;
            nxet = TRUE;
            price_20 = Bid;
         }
      }
      oraimo = oraim;
      snooze = dooze;
   }
   if (Alerts && nxet) {
      PlaySound("alert.wav");
      if (oraimo == 1) MessageBox("Entry point: buy at " + price_20 + "!!", "Entry Point", 0);
      else
         if (oraimo == 2) MessageBox("Entry point: sell at " + price_20 + "!!", "Entry Point", 0);
      nxet = FALSE;
   }
   return (0);
}