
// #4X 2010 Candle D1-H4      \¦/
// Knowledge of the ancients (ò ó)
//______________________o0o___(_)___o0o_____
//___¦Xard777¦_____¦_____¦_____¦_____¦_2010_¦

#property indicator_chart_window

extern double PeriodX = PERIOD_H4;
extern bool AutoSelect.TF=true;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
if (AutoSelect.TF) {
      int aPeriod=Period();
      switch(aPeriod) {
         case 1 :     PeriodX=PERIOD_M5; break;
         case 5 :     PeriodX=PERIOD_M15; break;
         case 15 :    PeriodX=PERIOD_M30; break;
         case 30 :    PeriodX=PERIOD_H1; break;
         case 60 :    PeriodX=PERIOD_H4; break;
         case 240 :   PeriodX=PERIOD_D1; break;
         case 1440 :  PeriodX=PERIOD_W1; break;
         case 10080 : PeriodX=PERIOD_MN1; break;
         case 43200 : PeriodX=PERIOD_MN1; break;
      }
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
  for (int i=0; i<10; i++) {
    ObjectDelete("BD"+i);
    ObjectDelete("SD"+i);    
  } 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   if(Period() >= PeriodX) return(0);
   
   double dailyHigh[10], dailyLow[10], dailyOpen[10], dailyClose[10];
         
   ArrayCopySeries(dailyHigh,MODE_HIGH,Symbol(),PeriodX);
   ArrayCopySeries(dailyLow,MODE_LOW,Symbol(),PeriodX);
   ArrayCopySeries(dailyOpen,MODE_OPEN,Symbol(),PeriodX);
   ArrayCopySeries(dailyClose,MODE_CLOSE,Symbol(),PeriodX);

   color cl;
   
   datetime t1;
   datetime t2;
   
   int i,j=3;
   for (i=2;i>=0;i--){
      t1=Time[0]+(Period()*(j*90));
      t2=Time[0]+(Period()*(j+1)*90);
      if(ObjectFind("BD"+i)==-1){
         if (dailyOpen[i]>dailyClose[i]) cl=C'170,34,34'; else cl=C'0,128,0';
         CreateObjects("D"+i,t1,t2,dailyOpen[i],dailyClose[i],dailyLow[i],dailyHigh[i],cl);
      }else{
         if (dailyOpen[i]>dailyClose[i]) cl=C'170,34,34'; else cl=C'0,128,0';
         DrawObjects("D"+i,t1,t2,dailyOpen[i],dailyClose[i],dailyLow[i],dailyHigh[i],cl);      
      }
      j++;
      j++;
      //Comment(dailyClose[i]);
   }
   
   
   
   return(0);
  }
//+------------------------------------------------------------------+
void CreateObjects(string no, datetime dt1, datetime dt2, double po, double pc, double pl,double ph, color cl) {
  if (po==pc) cl=Gray;
  
  ObjectCreate("B"+no, OBJ_RECTANGLE, 0, dt1,po, dt2, pc);
  ObjectSet("B"+no, OBJPROP_STYLE, STYLE_SOLID);
  ObjectSet("B"+no, OBJPROP_COLOR, cl);
  ObjectSet("B"+no, OBJPROP_BACK, True);
  datetime t=dt1+((dt2-dt1)/2);
  ObjectCreate("S"+no, OBJ_TREND, 0, t, pl, t, ph);
  ObjectSet("S"+no, OBJPROP_COLOR, cl);
  ObjectSet("S"+no, OBJPROP_BACK, true);
  ObjectSet("S"+no, OBJPROP_RAY, False);
  ObjectSet("S"+no, OBJPROP_WIDTH, 2);
}
void DrawObjects(string no, datetime dt1, datetime dt2, double po, double pc, double pl,double ph, color cl) {
  if (po==pc) cl=Gray;
    
  ObjectSet("B"+no, OBJPROP_TIME1 , dt1);
  ObjectSet("B"+no, OBJPROP_PRICE1, po);
  ObjectSet("B"+no, OBJPROP_TIME2 , dt2);
  ObjectSet("B"+no, OBJPROP_PRICE2, pc);
  ObjectSet("B"+no, OBJPROP_BACK, true);
  ObjectSet("B"+no, OBJPROP_COLOR, cl);
  datetime t=dt1+((dt2-dt1)/2);
  ObjectSet("S"+no, OBJPROP_TIME1 , t);
  ObjectSet("S"+no, OBJPROP_PRICE1, pl);
  ObjectSet("S"+no, OBJPROP_TIME2 , t);
  ObjectSet("S"+no, OBJPROP_PRICE2, ph);
  ObjectSet("S"+no, OBJPROP_BACK, true);
  ObjectSet("S"+no, OBJPROP_WIDTH, 2);
  ObjectSet("S"+no, OBJPROP_COLOR, cl);
  
  
}

