#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 MediumBlue
#property indicator_color2 Crimson


extern bool EmailAlert=false;
extern bool AudioAlert=true;

//---------------Waddah Settings----------
extern double Minutes = 0;
extern double MinutesUpper = 240;
extern int  Sensetive = 150;
extern int  DeadZonePip = 15;
extern int  ExplosionPower = 15;
extern int  TrendPower = 15;
extern bool AlertWindow = false;
extern int  AlertCount = 20;
extern bool AlertLong = true;
extern bool AlertShort = true;
extern bool AlertExitLong = true;
extern bool AlertExitShort = true;
 
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID, 0);
   SetIndexArrow(0,233);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID, 0);
   SetIndexArrow(1,234);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);

  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
   int shift;
   bool up1, up2, down1, down2, mWasUp = true, mWasDown = false;
   for(shift=Bars-1;shift>=0;shift--)
   {	
   
      ExtMapBuffer1[shift] = 0; ExtMapBuffer2[shift] = 0;
      
      double WaddahUP = iCustom(NULL,0,"MTF_Waddah_Attar_ExplosionSA",Minutes,Sensetive,DeadZonePip,ExplosionPower,TrendPower,AlertWindow,AlertCount,AlertLong,AlertShort,AlertExitLong,AlertExitShort,0,shift);   
      double WaddahDN = iCustom(NULL,0,"MTF_Waddah_Attar_ExplosionSA",Minutes,Sensetive,DeadZonePip,ExplosionPower,TrendPower,AlertWindow,AlertCount,AlertLong,AlertShort,AlertExitLong,AlertExitShort,1,shift);
      double WaddahUpUpper = iCustom(NULL,0,"MTF_Waddah_Attar_ExplosionSA",MinutesUpper,Sensetive,DeadZonePip,ExplosionPower,TrendPower,AlertWindow,AlertCount,AlertLong,AlertShort,AlertExitLong,AlertExitShort,0,shift+1);   
      double WaddahDnUpper = iCustom(NULL,0,"MTF_Waddah_Attar_ExplosionSA",MinutesUpper,Sensetive,DeadZonePip,ExplosionPower,TrendPower,AlertWindow,AlertCount,AlertLong,AlertShort,AlertExitLong,AlertExitShort,1,shift+1);
      double WaddahTriggerLine = iCustom(NULL,0,"MTF_Waddah_Attar_ExplosionSA",Minutes,Sensetive,DeadZonePip,ExplosionPower,TrendPower,AlertWindow,AlertCount,AlertLong,AlertShort,AlertExitLong,AlertExitShort,2,0);
      double WaddahTriggerLineUpper = iCustom(NULL,0,"MTF_Waddah_Attar_ExplosionSA",MinutesUpper,Sensetive,DeadZonePip,ExplosionPower,TrendPower,AlertWindow,AlertCount,AlertLong,AlertShort,AlertExitLong,AlertExitShort,2,0);
     
      
      if ((WaddahUP > WaddahTriggerLine) && (WaddahUpUpper > 0)) up1=true; else up1=false; 
      if ((WaddahDN > WaddahTriggerLine) && (WaddahDnUpper > 0)) down1=true; else down1=false;      
  
//      if ((WaddahUpUpper > WaddahTriggerLineUpper) && (WaddahUpUpper > 0)) up2=true; else up2=false;
//      if ((WaddahDN > WaddahTriggerLine) && (WaddahDnUpper > 0)) down2=true; else down2=false;
       
      if (up1 && mWasDown)
        { 
          ExtMapBuffer1[shift] = Low[shift] - 35 * Point;
          mWasUp = true;
          mWasDown = false;
        }
   
      if (down1 && mWasUp)
        {
          ExtMapBuffer2[shift] = High[shift] + 35 * Point; 
          mWasUp = false;
          mWasDown = true;
        }
   }
   if (AudioAlert)
   {
   static int audio;
   if ((ExtMapBuffer1[1]!=0 /*&& ExtMapBuffer1[2]==0*/) && audio!=1)
   {audio=1; Alert ("BUY on ",Symbol()," ",Period()," Minute Chart");}
   if ((ExtMapBuffer2[1]!=0 /*&& ExtMapBuffer2[2]==0*/) && audio!=-1)
      {audio=-1; Alert ("SELL on  ",Symbol()," ",Period()," Minute Chart");}
   }
   
   if (EmailAlert)
   {
   static int email;
   if ((ExtMapBuffer1[1]!=0 && ExtMapBuffer1[2]==0) && email!=1)
   {email=1; SendMail ("BUY on "+Symbol()+" "+Period()+" Minute Chart","");}
   if ((ExtMapBuffer2[1]!=0 && ExtMapBuffer2[2]==0) && email!=-1)
      {email=-1; SendMail ("SELL on  "+Symbol()+" "+Period()+" Minute Chart","");}
   }


}