//+------------------------------------------------------------------------------+
//|                                            Sonic_Ind_v2.2.mq4               |
//|                                            Copyright © 2008, DGC,Sonicdeejay |
//|                                         http://tinyurl.com/497h3s            |
//+------------------------------------------------------------------------------+

/* =============== Updates by Smartman
:: 27-08-2008: Added: GmailSendLibrary support
*/

#property copyright "Copyright © 2008, DGC & SonicDeejay"
#property link      "http://tinyurl.com/497h3s"

#include <WinUser32.mqh>

//SM 27/08/08
#include <GmailSendLibrary.mqh>

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Brown
#property indicator_width1 2
#property indicator_minimum -1.2
#property indicator_maximum 1.2

extern string SEP1 = "----SIGNAL CONTROLS----";
extern bool Show_Sonic_Signals = true;


//extern bool SoundAlert = true;
extern string SEP3 = "----ALERT CONTROLS----";
extern bool Popup_Alerts_On = false;
extern bool Audio_Alerts_On = false;
extern bool EMail_Alerts_On = false;

//SM 27/08/08
extern string sComment1       = "====== Gmail configuration =======";
extern bool   gMail_Account   = false;                       // true for using a gmail account
extern string gmailUsername   = "youremail@gmail.com";
extern string gmailPassword   = "your_gmail_password";
//extern string gmailFrom       = "youremail@gmail.com";
extern string gmailTo         = "to@any_email_server.com";   // or the same "youremail@gmail.com"
extern string gmailSubject    = "Subject";
extern string gmailMessage    = "Message";


double Sonic[];

int iLastRegular;
double dLastAES;
int k;
int buyflag;
int sellflag;


bool bAlertSounded;

int init()
{
   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(0, Sonic);
   iLastRegular = 0;
   dLastAES = 0;
   bAlertSounded = false;
   IndicatorShortName("Sonic Striker Indicator V2.3");
   return(0);
}

int start()
{

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
   for (k = Bars - 205; k >= 0; k --)
   {

       double  AC1 = iAC(Symbol(), 0, k);
       double  AC2 = iAC(Symbol(), 0, k+1);
       double  AC3 = iAC(Symbol(), 0, k+2);

       
       double  STOMAIN1 = iStochastic(NULL, 0, 5, 3, 3, MODE_EMA, 1, MODE_MAIN, k);
       double  STOMAIN2 = iStochastic(NULL, 0, 5, 3, 3, MODE_EMA, 1, MODE_MAIN, k+1);
       double  STOSIG1  = iStochastic(NULL, 0, 5, 3, 3, MODE_EMA, 1, MODE_SIGNAL, k);
       double  STOSIG2  = iStochastic(NULL, 0, 5, 3, 3, MODE_EMA, 1, MODE_SIGNAL, k+1);
       
       double  RSIV = iRSI(NULL, 0, 14, 0, k);
       
       double  ADXGreen1 = iCustom (NULL,0,"Advanced_ADX",14,0,k);
       double  ADXGreen2 = iCustom (NULL,0,"Advanced_ADX",14,0,k+1);
       double  ADXRed1 = iCustom (NULL,0,"Advanced_ADX",14,1,k);
       double  ADXRed2 = iCustom (NULL,0,"Advanced_ADX",14,1,k+1);
       
       
       double  MOM = iMomentum( NULL,0, 14, PRICE_CLOSE, k); 
       double  SLDRED = iCustom( NULL,0,"Slope Direction Line",30,3,0,0, k); 
       double  SLDBLU = iCustom( NULL,0,"Slope Direction Line",30,3,0,1, k); 
       
/*---------------------*/            
/*  SONIC SINGAL CODE  */
/*---------------------*/
      Sonic[k] = 0;
      
      if (((AC1>0||(AC1>AC2)))&&(STOMAIN1>STOSIG1)&&(STOMAIN1>STOMAIN2)&&(RSIV>52)&&((ADXGreen1>15)||(ADXRed1>25)))
     
                 
      {
         if (iLastRegular == -1 || iLastRegular==0)  Sonic[k] = 1;
         iLastRegular = 1;
      }   
      
      if (((AC1<0)||(AC1<AC2))&&(STOMAIN1<STOSIG1)&&(STOSIG1<STOSIG2)&&(RSIV<48)&&((ADXGreen1>25)||(ADXRed1>15)))
      
                 
      {
         if (iLastRegular == 1 || iLastRegular==0) Sonic[k] = -1;
         iLastRegular = -1;
      }   
      if (Show_Sonic_Signals == false) Sonic[k] = 0.0;
      
    
      if(iLastRegular==1 && AC1<0 && AC2>0)
         iLastRegular=0;
      
      
      if(iLastRegular==-1 && AC1>0 && AC2<0)
         iLastRegular=0;


/////////////////////////////////////////////////////////////////////////////////////////////////////////////

  
    

   }

/*--------------*/            
/*  ALERT CODE  */
/*--------------*/   


   
            if (Sonic[0] != 0 && bAlertSounded == false)
            {
               if (Popup_Alerts_On == true)
                  MessageBox("alert", "Sonic Trade Alert!!", MB_OK);
               if (Audio_Alerts_On == true)
                  PlaySound("Alert.wav");
                  
               //SM 27/08/08
               if (EMail_Alerts_On == true)
               {
                  if ( !gMail_Account )
                  {
                  SendMail("Sonic Trade Alert!!", "alert");
                  }
                  else
                  {
                    if ( !SendGmail(gmailUsername, gmailTo, gmailSubject, gmailMessage,
                                 gmailUsername, gmailPassword)
                       )
                       Alert("Error sending email through gmail");
                  }  
               }   
               bAlertSounded = true;
            }
            else bAlertSounded = false;
            
 
        

   return(0);
}

