//+------------------------------------------------------------------+
//|                                                CandleHighLow.mq4 |
//|                                                            GumRai
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "GumRai"
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
//--- input parameters
extern bool      DailyHighLow=true;
extern bool      WeeklyHighLow=true;
extern bool      MonthlyHighLow=true;
extern color     Colour_High=Blue;
extern color     Colour_Low=Red;
extern int       HistoryBars =200;
extern bool      ShowText=false;

int offset;
string MonthArray[13];
string storeobname[4020];
int storecount =0;
int ArrCode=1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

MonthArray [1]="Jan";
MonthArray [2]="Feb";
MonthArray [3]="Mar";
MonthArray [4]="Apr";
MonthArray [5]="May";
MonthArray [6]="June";
MonthArray [7]="July";
MonthArray [8]="Aug";
MonthArray [9]="Sept";
MonthArray [10]="Oct";
MonthArray [11]="Nov";
MonthArray [12]="Dec";

int tf=Period( ) ;
offset = tf*60;


//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
   for( int i=storecount-1;i>=0;i--)
   {
  
   if(ObjectFind( storeobname[i]) !=-1)
   ObjectDelete(storeobname[i] ) ;
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
//----
   for( int i=storecount-1;i>=0;i--)
   {
  
   if(ObjectFind( storeobname[i]) !=-1)
   ObjectDelete(storeobname[i] ) ;
   }
   storecount=0;
   datetime timeindex = Time[0];
   
 if(DailyHighLow==true)
 {  
   int suncount=0;
   for(i=1;i<=HistoryBars;i++)
   {
   if(storecount>=4000) break;
   double Dayhigh =iHigh(NULL,PERIOD_D1,i+suncount);
   double Daylow =iLow(NULL,PERIOD_D1,i+suncount);   
   datetime Daytime=iTime(NULL,PERIOD_D1,i+suncount);
   int  date=TimeDay(Daytime);
   int yr=TimeYear(Daytime); 
   
   //Alert(TimeDayOfWeek(Daytime));
         if(TimeDayOfWeek(Daytime)==1 &&  TimeDayOfWeek(iTime(NULL,PERIOD_D1,i+1+suncount))==0)
           {
           //Alert("i= ",i);
           double sunhigh=iHigh(NULL,PERIOD_D1,i+1+suncount);
           double sunlow=iLow(NULL,PERIOD_D1,i+1+suncount);
           if(sunhigh>Dayhigh) Dayhigh=sunhigh;
           if(sunlow<Daylow) Daylow=sunlow;
           suncount++;
           }
   
   string month=MonthArray[TimeMonth(Daytime)];
   string linename ="Daily High "+ date+" "+month+" "+yr;
     if(ObjectFind(linename) ==-1)
      {
      ObjectCreate(linename,OBJ_HLINE,0,Daytime,Dayhigh);
      ObjectSet( linename,OBJPROP_COLOR,Colour_High); 
      ObjectSet( linename,OBJPROP_BACK,true); 
      ObjectSet( linename,OBJPROP_STYLE,STYLE_DOT);
      storeobname[storecount]=linename;
      storecount++;
      
      
     if(ShowText)
       {
       linename =linename+" text";
       if(ObjectFind(linename) ==-1)
         {
         ObjectCreate(linename,OBJ_TEXT,0,timeindex+offset,Dayhigh);
         ObjectSet( linename,OBJPROP_ANGLE,90);        
         ObjectSetText(linename,"Dly Hi "+ date+" "+month+" "+yr,8,"arial",Colour_High);
         storeobname[storecount]=linename;
         storecount++;
         
         linename =linename+"Arrow";
         ObjectCreate(linename,OBJ_ARROW,0,timeindex+offset,Dayhigh);
         ObjectSet( linename,OBJPROP_ARROWCODE,ArrCode);
         ObjectSet( linename,OBJPROP_COLOR,Colour_High);
         //timeindex=timeindex+(2*offset);
         storeobname[storecount]=linename;
         storecount++;  
         }
       }
      }  
   linename ="Daily Low "+ date+" "+month+" "+yr;
      if(ObjectFind(linename) ==-1)
      {
      ObjectCreate(linename,OBJ_HLINE,0,Daytime,Daylow);
      ObjectSet( linename,OBJPROP_COLOR,Colour_Low); 
      ObjectSet( linename,OBJPROP_BACK,true); 
      ObjectSet( linename,OBJPROP_STYLE,STYLE_DOT);
      
      storeobname[storecount]=linename;
      storecount++;
      
   if(ShowText)
       {
       linename =linename+" text";
       if(ObjectFind(linename) ==-1)
         {
         ObjectCreate(linename,OBJ_TEXT,0,timeindex+offset,Daylow);         
         ObjectSetText(linename,"Dly Lo "+ date+" "+month+" "+yr,8,"arial",Colour_Low);
         ObjectSet( linename,OBJPROP_ANGLE,90);
         storeobname[storecount]=linename;
         storecount++;
         
         linename =linename+"Arrow";
         ObjectCreate(linename,OBJ_ARROW,0,timeindex+offset,Daylow);
         ObjectSet( linename,OBJPROP_ARROWCODE,ArrCode);
         ObjectSet( linename,OBJPROP_COLOR,Colour_Low);
         timeindex=timeindex+(2*offset);
         storeobname[storecount]=linename;
         storecount++;  
         }
       }
      }   
   }
 } 
   
 if(MonthlyHighLow==true)
 {
   for(i=1;i<=HistoryBars;i++)
   {
   if(storecount>=4000) break;
   double Monhigh =iHigh(NULL,PERIOD_MN1,i);
   double Monlow =iLow(NULL,PERIOD_MN1,i);   
   datetime Montime=iTime(NULL,PERIOD_MN1,i);
   yr=TimeYear(Montime);
   month=MonthArray[TimeMonth(Montime)];
   
   linename ="Monthly High "+ month+" "+yr;
     if(ObjectFind(linename) ==-1)
      {
      ObjectCreate(linename,OBJ_HLINE,0,Montime,Monhigh);
      ObjectSet( linename,OBJPROP_COLOR,Colour_High); 
      ObjectSet( linename,OBJPROP_BACK,true);
      storeobname[storecount]=linename;
      storecount++;
      
      if(ShowText)
       {
       linename =linename+" text"+" "+yr;
       if(ObjectFind(linename) ==-1)
         {
         ObjectCreate(linename,OBJ_TEXT,0,timeindex+offset,Monhigh);
         ObjectSet( linename,OBJPROP_ANGLE,90);        
         ObjectSetText(linename,"Monthly High "+ month+" "+yr,8,"arial",Colour_High);
         storeobname[storecount]=linename;
         storecount++;
         
         linename =linename+"Arrow";
         ObjectCreate(linename,OBJ_ARROW,0,timeindex+offset,Monhigh);
         ObjectSet( linename,OBJPROP_ARROWCODE,ArrCode);
         ObjectSet( linename,OBJPROP_COLOR,Colour_High);
         //timeindex=timeindex+(2*offset);
         storeobname[storecount]=linename;
         storecount++;  
         }
       }
      
      }  
   linename ="Monthly Low "+month+" "+yr;
     if(ObjectFind(linename) ==-1)
     {
      ObjectCreate(linename,OBJ_HLINE,0,Montime,Monlow);
      ObjectSet( linename,OBJPROP_COLOR,Colour_Low); 
      ObjectSet( linename,OBJPROP_BACK,true);
      storeobname[storecount]=linename;
      storecount++;
      
      if(ShowText)
       {
       linename =linename+" text";
       if(ObjectFind(linename) ==-1)
         {
         ObjectCreate(linename,OBJ_TEXT,0,timeindex+offset,Monlow);
         ObjectSet( linename,OBJPROP_ANGLE,90);        
         ObjectSetText(linename,"Monthly Low "+ month+" "+yr,8,"arial",Colour_Low);
         storeobname[storecount]=linename;
         storecount++;
         
         linename =linename+"Arrow";
         ObjectCreate(linename,OBJ_ARROW,0,timeindex+offset,Monlow);
         ObjectSet( linename,OBJPROP_ARROWCODE,ArrCode);
         ObjectSet( linename,OBJPROP_COLOR,Colour_Low);
         timeindex=timeindex+(2*offset);
         storeobname[storecount]=linename;
         storecount++;  
         }
       }
     }  
   
   }   
}  

if(WeeklyHighLow==true)
 {
   for(i=1;i<=HistoryBars;i++)
   {
   if(storecount>=4000) break;
   double Weekhigh =iHigh(NULL,PERIOD_W1,i);
   double Weeklow =iLow(NULL,PERIOD_W1,i);   
   datetime Weektime=iTime(NULL,PERIOD_W1,i);
   date=TimeDay(Weektime);
   yr=TimeYear(Weektime);
   month=MonthArray[TimeMonth(Weektime)];
   
   linename ="Weekly High "+date+ month+" "+yr;
     if(ObjectFind(linename) ==-1)
      {
      ObjectCreate(linename,OBJ_HLINE,0,Weektime,Weekhigh);
      ObjectSet( linename,OBJPROP_COLOR,Colour_High); 
      ObjectSet( linename,OBJPROP_BACK,true);
      ObjectSet( linename,OBJPROP_STYLE,STYLE_DASHDOT);
      storeobname[storecount]=linename;
      storecount++;
      
      if(ShowText)
       {
       linename =linename+" text";
       if(ObjectFind(linename) ==-1)
         {
         ObjectCreate(linename,OBJ_TEXT,0,timeindex+offset,Weekhigh);
         ObjectSet( linename,OBJPROP_ANGLE,90);         
         ObjectSetText(linename,"Weekly High "+date+ month+" "+yr,8,"arial",Colour_High);
         storeobname[storecount]=linename;
         storecount++;
         
         linename =linename+"Arrow";
         ObjectCreate(linename,OBJ_ARROW,0,timeindex+offset,Weekhigh);
         ObjectSet( linename,OBJPROP_ARROWCODE,ArrCode);
         ObjectSet( linename,OBJPROP_COLOR,Colour_High);
         //timeindex=timeindex+(2*offset);
         storeobname[storecount]=linename;
         storecount++;  
         }
       }
      }  
   linename ="Weekly Low "+date+" "+month+" "+yr;
     if(ObjectFind(linename) ==-1)
     {
      ObjectCreate(linename,OBJ_HLINE,0,Weektime,Weeklow);
      ObjectSet( linename,OBJPROP_COLOR,Colour_Low); 
      ObjectSet( linename,OBJPROP_BACK,true);
      ObjectSet( linename,OBJPROP_STYLE,STYLE_DASHDOT);
      storeobname[storecount]=linename;
      storecount++;
      
      if(ShowText)
       {
       linename =linename+" text";
       if(ObjectFind(linename) ==-1)
         {
         ObjectCreate(linename,OBJ_TEXT,0,timeindex+offset,Weeklow);
         ObjectSet( linename,OBJPROP_ANGLE,90);         
         ObjectSetText(linename,"Weekly Low "+date+ month+" "+yr,8,"arial",Colour_Low);
         storeobname[storecount]=linename;
         storecount++;
         
         linename =linename+"Arrow";
         ObjectCreate(linename,OBJ_ARROW,0,timeindex+offset,Weeklow);
         ObjectSet( linename,OBJPROP_ARROWCODE,ArrCode);
         ObjectSet( linename,OBJPROP_COLOR,Colour_Low);
         timeindex=timeindex+(2*offset);
         storeobname[storecount]=linename;
         storecount++;  
         }
       }
     }  
   
   }   
}  
   

   
//----
   return(0);
  }
//+------------------------------------------------------------------+


