//+------------------------------------------------------------------+
//|                                                  4TF HAS Bar.mq4 |
//|                  Modified by Matsu, from #MTF Supertrend Bar.mq4 |
//|                                      Copyright © 2006, Eli hayun |
//|                                          http://www.elihayun.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Eli hayun"
#property link      "http://www.elihayun.com"
//----
#property indicator_separate_window
#property indicator_minimum 1
#property indicator_maximum 2
#property indicator_buffers 2
//----
#property indicator_color1 Blue
#property indicator_color2 Red

//---- parameters


extern int BarWidth=0;

extern color TextColor=White;
extern int MaxBars=500;
extern int Period_1=1;
 double shift=0.2;
 double gp=1;

//---- buffers
double buf4_up[];
double buf4_down[];
double buf3_up[];
double buf3_down[];
double buf2_up[];
double buf2_down[];
double buf1_up[];
double buf1_down[];
double haOpen;
double haClose;
double haOpen2;
double haClose2;
string shortname="";
//----
int ArrSize=110;//159;
int UniqueNum=2282;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0,DRAW_ARROW,0,BarWidth);
   SetIndexArrow(0,ArrSize);
   SetIndexBuffer(0,buf1_up);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW,0,BarWidth);
   SetIndexArrow(1,ArrSize);
   SetIndexBuffer(1,buf1_down);
   SetIndexEmptyValue(1,0.0);

   
  
//----
   SetIndexLabel(0,NULL);
   SetIndexLabel(1,NULL);
   

//----
   shortname="Off chart HAS ("+Period_1+")";
   IndicatorShortName(shortname);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- the last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   int i,tf;
//-------------------------------1----------------------------------------   
   double dif=Time[0] - Time[1];
   for( i=ObjectsTotal()-1; i>-1; i--)
     {
      if (StringFind(ObjectName(i),"FF_"+UniqueNum+"_")>=0)  ObjectDelete(ObjectName(i));
     }
   
   
      string txt="??";

    
        txt=tf2txt(Period_1); 
        
       
      string name="FF_"+UniqueNum+"_"+tf+"_"+txt;
      ObjectCreate(name, OBJ_TEXT, WindowFind(shortname), iTime(NULL,0,0)+dif*1, gp);
      ObjectSetText(name, txt,8,"Arial", TextColor);
    
//-------------------------------2----------------------------------------
   datetime  TimeArray_1[];
   ArrayCopySeries(TimeArray_1,MODE_TIME,Symbol(),Period_1);

   int  i1=0, yy;
 
   for(i=0, i1=0;i<limit;i++)
     {
      if (Time[i]<TimeArray_1[i1]) i1++;
     
//----
      
         int prd;
        
         prd=Period_1; yy=i1; 
           
          
        haOpen=iCustom(NULL,prd,"HeikenAshi_DM",2,yy) ;
         haClose=iCustom(NULL,prd,"HeikenAshi_DM",3,yy) ; 
         
           buf1_down[i]=EMPTY_VALUE;
           buf1_up[i]=EMPTY_VALUE;  
           if (haOpen>=haClose)  buf1_down[i]=1;           
           else buf1_up[i]=1;     
            
      
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string tf2txt(int tf)
  {
   if (tf==PERIOD_M1)    return("M1");
   if (tf==PERIOD_M5)    return("M5");
   if (tf==PERIOD_M15)   return("M15");
   if (tf==PERIOD_M30)   return("M30");
   if (tf==PERIOD_H1)    return("H1");
   if (tf==PERIOD_H4)    return("H4");
   if (tf==PERIOD_D1)    return("D1");
   if (tf==PERIOD_W1)    return("W1");
   if (tf==PERIOD_MN1)   return("MN");
   return("??");
}
//+------------------------------------------------------------------+