//+------------------------------------------------------------------+
//|                                          Heiken ashi MTF sw v1.2 |
//|                                               Versions changelog |
//|                                        original indicator - v1.0 |
//|                                   added BarsNumber option - v1.1 |
//|                             added choosable symbol option - v1.2 |
//+------------------------------------------------------------------+


#property copyright   "Fausto Del Gaudio"
#property link        "mailto: thefxpros@katamail.com"
#property description "Heiken ashi chart in the subwindow with multi timeframe and choosable symbol ability"
#property version     "1.2"
#property strict




#property indicator_separate_window
#property indicator_buffers 6

#property indicator_color1 OrangeRed //sellbody
#property indicator_color2 SteelBlue //buybody
#property indicator_color4 Brown     //sellwick
#property indicator_color5 DarkBlue  //buywick
#property indicator_color3 Lavender
#property indicator_color6 Lavender

#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 1
#property indicator_width5 1
#property indicator_width6 1



extern string  PARAMETERS  = "==== HEIKEN ASHI MTF SW PARAMETERS ====";
extern int     TimeFrame   = 0;           //Select timeframe to use (0=current)
extern int     xShift      = 0;           //Horizontal shift
extern string  Symbol_Name = "";          //Symbol (leave blank for current symbol)
extern int     BarsNumber  = 200;         //History bars to show 

extern string  GRAPHICS    = "==== HEIKEN ASHI MTF SW GRAPHICS ====";
extern color   WickUpColor = DarkBlue;    //Color of Bull candles wick
extern color   WickDnColor = Brown;       //Color of Bear candles wick
extern color   BodyUpColor = SteelBlue;   //Color of Bull candles body
extern color   BodyDnColor = OrangeRed;   //Color of Bear candles body

extern int     WickWidth   = 1;           //Width of candles wick
extern int     BodyWidth   = 2;           //Width of candles body


string TimeFrameStr;
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
  {
   color bg=(color)ChartGetInteger(ChartID(),CHART_COLOR_BACKGROUND);

   if(TimeFrame==0) TimeFrame = Period();
   
   if (Symbol_Name == "") Symbol_Name = Symbol();
   
 //---- indicator line
      
   
   SetIndexBuffer(3,ExtMapBuffer1);
   SetIndexStyle (3,DRAW_HISTOGRAM,0,WickWidth,WickDnColor);
   SetIndexLabel (3,NULL);
   SetIndexShift (3,xShift*TimeFrame/Period());
   
   SetIndexBuffer(4,ExtMapBuffer2);
   SetIndexStyle (4,DRAW_HISTOGRAM,0,WickWidth,WickUpColor);
   SetIndexLabel (4,NULL);
   SetIndexShift (4,xShift*TimeFrame/Period());   
     
   SetIndexBuffer(0,ExtMapBuffer3);  
   SetIndexStyle (0,DRAW_HISTOGRAM,0,BodyWidth,BodyDnColor);
   SetIndexLabel (0,NULL);   
   SetIndexShift (0,xShift*TimeFrame/Period());
      
   SetIndexBuffer(1,ExtMapBuffer4); 
   SetIndexStyle (1,DRAW_HISTOGRAM,0,BodyWidth,BodyUpColor);
   SetIndexLabel (1,NULL);
   SetIndexShift (1,xShift*TimeFrame/Period()); 
    
   SetIndexBuffer(5,ExtMapBuffer5);
   SetIndexStyle (5,DRAW_HISTOGRAM,0,BodyWidth-1,bg);
   SetIndexLabel (5,NULL);
   SetIndexShift (5,xShift*TimeFrame/Period()); 
   
   SetIndexBuffer(2,ExtMapBuffer6);
   SetIndexStyle (2,DRAW_HISTOGRAM,0,BodyWidth+1,bg);
   SetIndexLabel (2,NULL);
   SetIndexShift (2,xShift*TimeFrame/Period());    
   
  


   if (TimeFrame <= Period()) TimeFrame = Period();

//---- name for DataWindow and indicator subwindow label   
   switch(TimeFrame)
   {
      case 1 : TimeFrameStr="Period M1"; break;
      case 5 : TimeFrameStr="Period M5"; break;
      case 15 : TimeFrameStr="Period M15"; break;
      case 30 : TimeFrameStr="Period M30"; break;
      case 60 : TimeFrameStr="Period H1"; break;
      case 240 : TimeFrameStr="Period H4"; break;
      case 1440 : TimeFrameStr="Period D1"; break;
      case 10080 : TimeFrameStr="Period W1"; break;
      case 43200 : TimeFrameStr="Period MN1"; break;
      default : TimeFrameStr="Current Timeframe";
   }
   IndicatorShortName("Heiken ashi MTF sw ["+Symbol_Name+" - "+TimeFrameStr+"]");   
   return(0);
}
   
 
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int start()
  {
   int counted_bars = IndicatorCounted();
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
         int limit = MathMin(MathMax(Bars-counted_bars,3*TimeFrame/Period()),BarsNumber/*Bars-1*/);
   for(int i=limit;i>=0;i--)
   {
      int y = iBarShift(NULL,TimeFrame,Time[i]);
         ExtMapBuffer1[i]=iCustom(Symbol_Name,TimeFrame,"Heiken ashi",0,y);
         ExtMapBuffer2[i]=iCustom(Symbol_Name,TimeFrame,"Heiken ashi",1,y);
         ExtMapBuffer3[i]=iCustom(Symbol_Name,TimeFrame,"Heiken ashi",2,y);
         ExtMapBuffer4[i]=iCustom(Symbol_Name,TimeFrame,"Heiken ashi",3,y);
            ExtMapBuffer5[i]=MathMin(ExtMapBuffer1[i], ExtMapBuffer2[i]);
 	         ExtMapBuffer6[i]=MathMin(ExtMapBuffer3[i], ExtMapBuffer4[i]); 
   }  
   return(0);
}