//+------------------------------------------------------------------+
//| 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;
//+------------------------------------------------------------------+
enum enumar
  {
     cr,  // current
     cl   // close
  };
//+------------------------------------------------------------------+
extern bool   AlertsMessage   = true;        // Alert Message
extern bool   AlertsSound     = false;       // Alert Sound
extern bool   AlertsEmail     = false;       // Alert Email
extern bool   AlertsMobile    = false;       // Alert Mobile
extern string AlertsSoundFile = "alert.wav"; // Alert Sound File
extern enumar SignalBar       = 0;           // Signal Bar
//+------------------------------------------------------------------+
datetime TimeBar;
double g_ibuf_92[];
double g_ibuf_96[];
double g_ibuf_100[];
double g_ibuf_104[];
int trend = 0;
int lasttrend = 0;
double gd_116 = 0.0;
double gd_unused_124 = 0.0;

int init() {
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, g_ibuf_92);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, g_ibuf_96);
   SetIndexStyle(2, DRAW_ARROW);
   SetIndexArrow(2, 217);
   SetIndexBuffer(2, g_ibuf_100);
   SetIndexEmptyValue(2, 0.0);
   SetIndexStyle(3, DRAW_ARROW);
   SetIndexArrow(3, 218);
   SetIndexBuffer(3, g_ibuf_104);
   SetIndexEmptyValue(3, 0.0);
   return (0);
}

int deinit() {
   Comment("");
   return (0);
}

int start() {
   int li_4 = IndicatorCounted();
   double irsi_8 = 0;
   bool li_16 = FALSE;
   double price_20 = 0;
   if (li_4 < 0) return (-1);
   if (li_4 > 0) li_4--;
   int li_0 = Bars - li_4;
   for (int i = 0; i < li_0; i++)
    {
      g_ibuf_92[i] = iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      g_ibuf_96[i] = iMA(NULL, 0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      
      irsi_8 = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, i);
      gd_116 = g_ibuf_92[i] - g_ibuf_96[i];
      
      Comment("pipdiffCurrent = " + gd_116 + " ");
      
      if (gd_116 > 0.0 && irsi_8 > 50.0) trend = 1;
       else
        if (gd_116 < 0.0 && irsi_8 < 50.0) trend = 2;
         
      if (trend == 1 && lasttrend == 2)
       {
         g_ibuf_104[i-1] = High[i-1] + 5.0 * Point;
         li_16 = TRUE;
         price_20 = Ask;
       }else{
         if (trend == 2 && lasttrend == 1)
          {
            g_ibuf_100[i-1] = Low[i-1] - 5.0 * Point;
            li_16 = TRUE;
            price_20 = Bid;
          }
      }
      lasttrend = trend;
      gd_unused_124 = gd_116;
   }
  
  if(AlertsMessage || AlertsSound || AlertsEmail || AlertsMobile)
   { 
     string message1 = (WindowExpertName()+" - "+Symbol()+"  "+PeriodString()+" - Signal Up");
     string message2 = (WindowExpertName()+" - "+Symbol()+"  "+PeriodString()+" - Signal Dn");
       
     if(TimeBar!=Time[0] && g_ibuf_100[SignalBar]!=0 && g_ibuf_100[SignalBar]!=EMPTY_VALUE)
      { 
        if (AlertsMessage) Alert(message1);
        if (AlertsSound)   PlaySound(AlertsSoundFile);
        if (AlertsEmail)   SendMail(Symbol()+" - "+WindowExpertName()+" - ",message1);
        if (AlertsMobile)  SendNotification(message1);
       
        TimeBar = Time[0];
      }
     if(TimeBar!=Time[0] && g_ibuf_104[SignalBar]!=0 && g_ibuf_104[SignalBar]!=EMPTY_VALUE)
      { 
        if (AlertsMessage) Alert(message2);
        if (AlertsSound)   PlaySound(AlertsSoundFile);
        if (AlertsEmail)   SendMail(Symbol()+" - "+WindowExpertName()+" - ",message2);
        if (AlertsMobile)  SendNotification(message2);
       
        TimeBar = Time[0];
      }
    }
   return (0);
}
//+------------------------------------------------------------------+
//| Period String                                                    |
//+------------------------------------------------------------------+
string PeriodString()
  {
    switch (_Period) 
     {
        case PERIOD_M1:  return("M1");
        case PERIOD_M5:  return("M5");
        case PERIOD_M15: return("M15");
        case PERIOD_M30: return("M30");
        case PERIOD_H1:  return("H1");
        case PERIOD_H4:  return("H4");
        case PERIOD_D1:  return("D1");
        case PERIOD_W1:  return("W1");
        case PERIOD_MN1: return("MN1");
        default: return("M"+(string)_Period);
     }  
    return("M"+(string)_Period); 
  } 
//+------------------------------------------------------------------+