//+------------------------------------------------------------------+
//|                                                  Heiken Ashi.mq4 |
//|                      Copyright c 2004, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
//| For Heiken Ashi we recommend next chart settings ( press F8 or   |
//| select on menu 'Charts'->'Properties...'):                       |
//|  - On 'Color' Tab select 'Black' for 'Line Graph'                |
//|  - On 'Common' Tab disable 'Chart on Foreground' checkbox and    |
//|    select 'Line Chart' radiobutton                               |
//+------------------------------------------------------------------+
//mod by sangmane

#property copyright "Copyright ?2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Black 
#property indicator_color2 Black
#property indicator_color3 Red
#property indicator_color4 Blue
#property indicator_color5 DodgerBlue
#property indicator_color6 Yellow
#property indicator_width1 0
#property indicator_width2 0
#property indicator_width3 3
#property indicator_width4 3
#property indicator_width5 1
#property indicator_width6 1

//----
extern color color1 = Black;
extern color color2 = Black;
extern color color3 = Red;
extern color color4 = Blue;
extern int MaMethod  = 2;
extern int MaPeriod = 15;
extern int MaMethod2  = 2;
extern int MaPeriod2 = 15;
extern bool Notification = True;
extern bool Alert = True;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
string pair;
//----
int ExtCountedBars=0;
int tf;
datetime LastAlert;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|
int init()
  {
  pair=Symbol();
  
   
//---- indicators
   IndicatorBuffers(6);
   SetIndexStyle(0,DRAW_HISTOGRAM, 0, 0, color1);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM, 0, 0, color2);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM, 0, 3, color3);
   SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexStyle(3,DRAW_HISTOGRAM, 0, 3, color4);
   SetIndexBuffer(3, ExtMapBuffer4);
   
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4,233);
   SetIndexBuffer(4, ExtMapBuffer5);
   SetIndexStyle(5,DRAW_ARROW);
   SetIndexArrow(5,234);
   SetIndexBuffer(5, ExtMapBuffer6);      
//----
   SetIndexDrawBegin(0,10);
   SetIndexDrawBegin(1,10);
   SetIndexDrawBegin(2,10);
   SetIndexDrawBegin(3,10);
   SetIndexDrawBegin(4,10);
   SetIndexDrawBegin(5,10);   
   LastAlert = Time[0];
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   double haOpen, haHigh, haLow, haClose;
   if(Bars<=10) return(0);
   ExtCountedBars=IndicatorCounted();
//---- check for possible errors
   if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
   if (ExtCountedBars>0) ExtCountedBars--;
   int i=Bars-ExtCountedBars-1;
   while(i>=0)
     {
      ExtMapBuffer1[i] = iCustom(NULL,0,"Heiken_Ashi_Smoothed",MaMethod,MaPeriod,MaMethod2,MaPeriod2,0,i);
      ExtMapBuffer2[i] = iCustom(NULL,0,"Heiken_Ashi_Smoothed",MaMethod,MaPeriod,MaMethod2,MaPeriod2,1,i);
      ExtMapBuffer3[i] = iCustom(NULL,0,"Heiken_Ashi_Smoothed",MaMethod,MaPeriod,MaMethod2,MaPeriod2,2,i);
      ExtMapBuffer4[i] = iCustom(NULL,0,"Heiken_Ashi_Smoothed",MaMethod,MaPeriod,MaMethod2,MaPeriod2,3,i);
      
     if(ExtMapBuffer3[i+1]<ExtMapBuffer4[i+1] && ExtMapBuffer3[i+2]>=ExtMapBuffer4[i+2])
     {
       ExtMapBuffer5[i+1] = MathMin(Low[i+1],MathMin(ExtMapBuffer1[i+1],MathMin(ExtMapBuffer2[i+1],ExtMapBuffer3[i+1])));
       if(Time[i]>LastAlert)
       {
         LastAlert= Time[i];
         if(Notification) SendNotification(pair+" "+Period()+" Up at "+TimeToStr(Time[i],TIME_DATE|TIME_MINUTES));
         if (Alert) Alert(pair+Period()+"UP at "+TimeToStr(Time[i],TIME_DATE|TIME_MINUTES));
       }
     }
     else if(ExtMapBuffer3[i+1]>=ExtMapBuffer4[i+1] && ExtMapBuffer3[i+2]<ExtMapBuffer4[i+2])
     {
       ExtMapBuffer6[i+1] = MathMax(High[i+1],MathMax(ExtMapBuffer1[i+1],MathMax(ExtMapBuffer2[i+1],ExtMapBuffer3[i+1])));
       if(Time[i]>LastAlert)
       {
         LastAlert= Time[i];
         if(Notification) SendNotification(pair+" "+Period()+" Down at "+TimeToStr(Time[i],TIME_DATE|TIME_MINUTES));
         if(Alert) Alert(pair+Period()+"DOWN at ",TimeToStr(Time[i],TIME_DATE|TIME_MINUTES));
       }
     }          
 	   i--;
     }
     

    
//----
 return(0);
} 
  
//+------------------------------------------------------------------+