SR_AlertSystemM

Author: Steve Fleming
SR_AlertSystemM
11 Views
0 Downloads
0 Favorites
SR_AlertSystemM
//+------------------------------------------------------------------+
//|                                              #SR_AlertSystem.mq4 |
//|                                                    Steve Fleming |
//|                                         http://www.forexarea.com |
//+------------------------------------------------------------------+
#property copyright "Steve Fleming"
#property link      "http://www.forexarea.com"

#property indicator_chart_window
extern int     Timeframe       = 60; // 

extern bool    AlarmOn                 = true; // alarm on or off?
extern bool    SignalOnClose           = false; // if false we will use Bid price to signal piercing of S/R levels
extern string  ResistanceLineName      = "R_Alert"; // name of SR line that will trigger Alarm
extern string  SupportLineName         = "S_Alert"; // name of SR line that will trigger Alarm
extern string  SoundFile               = "alert2.wav"; //"mrplow.wav"; // name of sound file 
extern int     DelayBetweenAlarm       = 10; // 
extern color   SRLineClr               = DarkOrchid;  // color of SR lines
extern int     SRLineWidth             = 2;  // width of SR lines

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
	if(ObjectFind(ResistanceLineName) != 0){
	  ObjectCreate(ResistanceLineName, OBJ_HLINE, 0, 0,iHigh(NULL,Timeframe, 0));
	  ObjectSet(ResistanceLineName, OBJPROP_COLOR, SRLineClr);
	  ObjectSet(ResistanceLineName, OBJPROP_WIDTH, SRLineWidth);
	  ObjectCreate(SupportLineName, OBJ_HLINE, 0, 0,iLow(NULL,Timeframe, 0));
	  ObjectSet(SupportLineName, OBJPROP_COLOR, SRLineClr);
	  ObjectSet(SupportLineName, OBJPROP_WIDTH, SRLineWidth);
	}
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete(ResistanceLineName);
   ObjectDelete(SupportLineName);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
   if(AlarmOn){
      double PreviousClosePrice = Bid; 
      if(SignalOnClose == true){PreviousClosePrice = iClose(NULL,Timeframe, 1);}
      double ResistancePrice = ObjectGet(ResistanceLineName, OBJPROP_PRICE1);
      double SupportPrice = ObjectGet(SupportLineName, OBJPROP_PRICE1);
      if(PreviousClosePrice > ResistancePrice && ResistancePrice != 0)Alerts(1);
      if(PreviousClosePrice < SupportPrice && SupportPrice != 0)Alerts(2);
   }
//----ho ho ho!!!!
   return(0);
  }
//+------------------------------------------------------------------+

void Alerts(int Direction)
{
   static datetime AlertLastTime = 0;

   if(TimeCurrent() > AlertLastTime ) {
      AlertLastTime = TimeCurrent()+DelayBetweenAlarm;
      PlaySound(SoundFile);
   
   }
}

Comments