//+------------------------------------------------------------------+
//|                          Price Close Alert v1.2 EndLessSound.mq4 |
//|                                        Copyright © 2007, SMJones |
//|                                            sjcoinc2000@yahoo.com |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2007, SMJones (sjcoinc2000@yahoo.com)"
#property link      "http://forexBaron.net"

#property indicator_chart_window

extern int     TimeFrame = 0;//15;

extern double  PriceTest = 0.0;
extern string  csh="0:current candle, 1:previous candle,etc.";
extern int     CloseCandleShift=0;//fxdaytrader, 1:the last candle, 2:two candles ago, etc. pp.

extern bool    AlertAbove  = false,
               AlertBelow  = true,
               EmailAlertAbove=false,
               EmailAlertBelow=false,
               SendPushNotificationAbove=false,
               SendPushNotificationBelow=false,
               PlaySoundAbove=true,
               PlaySoundBelow=true;
extern string  SoundFileAbove="alert.wav",
               SoundFileBelow="alert2.wav";
string EndLessSoundFile="";

extern string  esh=":: if true and it starts playing -> remove the indicator or set \"EndLessSound\"=false to turn the Sound off!";
extern bool    EndLessSound=true;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
 if (TimeFrame==0) TimeFrame=Period();//fxdaytrader, makes sense for customer info purposes
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
      if (EndLessSoundFile!="") PlaySound(EndLessSoundFile);//EndLessSound, permanent PlaySound()-commands do not work, I assume because of diff. threads mt4 runs, not sure ..., fxdaytrader
      
      string msg;//fxdaytrader
      static int AlertPrevTime = 0;
      if (Time[0] <= AlertPrevTime) { 
      return;
      }
      bool alertaboveok=false;
      bool alertbelowok=false;
      
      if (CloseCandleShift>0) {alertaboveok=true; alertbelowok=true;}
      
      double testclose = iClose(NULL,TimeFrame,CloseCandleShift);
      
      if (CloseCandleShift==0) {//workaround for the current candle ...
       double testcloseb4 = iClose(NULL,TimeFrame,CloseCandleShift+1);
       
       if (testclose>PriceTest && testcloseb4<PriceTest) alertaboveok=true;
       if (testclose<PriceTest && testcloseb4>PriceTest) alertbelowok=true;
      }

      if(alertaboveok && testclose>PriceTest && PriceTest!=0)
       {
        msg=Symbol() + " Price Has Closed Above "+ DoubleToStr(PriceTest,MarketInfo(Symbol(),MODE_DIGITS)) + " On "+ TimeFrame+" Minute Bar";//fxdaytrader
        //if(AlertAbove)Alert(Symbol() + " Price Has Closed Above ", PriceTest, " On ", TimeFrame, " Minute Bar");
        //if(EmailAlertAbove)SendMail(Symbol() + " Price Close Alert!",Symbol() + " Price Has Closed Above "+PriceTest+" On "+TimeFrame+" Minute Bar");
        if(AlertAbove)Alert(msg);
        if(EmailAlertAbove)SendMail(Symbol() + " Price Close Alert!",msg);//fxdaytrader
        if(PlaySoundAbove) PlaySound(SoundFileAbove);//fxdaytrader
         if (EndLessSound) { EndLessSoundFile=SoundFileAbove; Alert(WindowExpertName()+"EndLessSound chosen -> remove the indicator or set \"EndLessSound\"=false to turn the Sound off!");} //fxdaytrader
        if(SendPushNotificationAbove) SendNotification(msg);//fxdaytrader
        AlertPrevTime  = Time[0];
       }
         
      //if(testclose<PriceTest)
      if(alertbelowok && testclose<PriceTest && PriceTest!=0)//fxdaytrader
       {
        msg=Symbol() + " Price Has Close Below "+ DoubleToStr(PriceTest,MarketInfo(Symbol(),MODE_DIGITS)) + " On "+ TimeFrame+ " Minute Bar";
        //if(AlertBelow)Alert(Symbol() + " Price Has Close Below ", PriceTest, " On ", TimeFrame, " Minute Bar"); 
        //if(EmailAlertBelow)SendMail(Symbol() + " Price Close Alert!",Symbol() + " Price Has Closed Below "+PriceTest+" On "+TimeFrame+" Minute Bar"); 
        if(AlertBelow)Alert(msg);//fxdaytrader
        if(EmailAlertBelow)SendMail(Symbol() + " Price Close Alert!",msg); //fxdaytrader
        if(PlaySoundBelow) PlaySound(SoundFileBelow);//fxdaytrader
         if (EndLessSound) { EndLessSoundFile=SoundFileBelow; Alert(WindowExpertName()+"EndLessSound chosen -> remove the indicator or set \"EndLessSound\"=false to turn the Sound off!");}//fxdaytrader
        if(SendPushNotificationBelow) SendNotification(msg);//fxdaytrader
        
        
        AlertPrevTime  = Time[0];
       }
//----
   return(0);
  }
//+------------------------------------------------------------------+