//+------------------------------------------------------------------+
//|                                                 lm_time_stat.mq4 |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property indicator_chart_window
// input parameters
//extern int MAX_HISTORY = 50;
//----
string OBJECT_PREFIX = "lm_time_stat";

//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Green
#property indicator_width1 3
#property indicator_width2 3
#property indicator_levelwidth 2000

//#property stacksize 1024

//--- buffers
double ExtBullsBuffer[];
double ExtBearsBuffer[];
    

//--- calc buffers
double bull[];
double bear[];
int bui[];
int bei[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
  
//--- 1 additional buffer used for counting.
   IndicatorBuffers(2);
   IndicatorDigits(Digits);
   IndicatorShortName("lm_time_stat");   

   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtBullsBuffer);
   SetIndexLabel(0,"UP");   
 
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,ExtBearsBuffer);
   SetIndexLabel(1,"DOWN");
   
//   SetIndexStyle(6,DRAW_LINE,STYLE_DOT);
//   SetIndexBuffer(6,ExtSpanB2_Buffer);
//   SetIndexDrawBegin(6,InpKijun+InpSenkou-1);
//   SetIndexShift(6,InpKijun);
//   SetIndexLabel(6,"Senkou Span B");
  
 //  OnTimer();
 //  EventSetTimer(60);
   return(0);
  }


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   //EventKillTimer();
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+


//  void OnTimer()
void calc()
  {
   int i,j;
   int limite=1439; // minute/jour -1
   int echantillon=14400;
   double cumul=0;
   
   ArrayResize(bull,limite+1); 
   ArrayResize(bear,limite+1); 
   ArrayFill(bull,0,limite,0); 
   ArrayFill(bear,0,limite,0);

   ArrayResize(bui,limite+1); 
   ArrayResize(bei,limite+1);    
   ArrayFill(bui,0,limite,0); 
   ArrayFill(bei,0,limite,0);
   
   //ChartSetSymbolPeriod(0,"",1);    
   
   for(i=0; i<=echantillon; i++)
     {
      j=(TimeHour(Time[i])*60)+TimeMinute(Time[i]);
      if (Close[i]>Open[i])
        { bull[j]+= High[i]-Low[i];
        bui[j]++; }
      else
        { bear[j]+= Low[i]-High[i];
        bei[j]++; } 
     }
   

   for( i=0; i<=limite; i++)
     {
      ExtBullsBuffer[i]=bull[i]/bui[i];
      ExtBearsBuffer[i]=bear[i]/bei[i];     
     }
     
   //  for(i=Bars-2; i>=0; i--) 
  //   { 
  //    if(High[i+1] > LastHigh) LastHigh = High[i+1]; 
   //   if(Low[i+1] < LastLow)   LastLow  = Low[i+1]; 
      //---- 
   //   if(TimeDay(Time[i]) != TimeDay(Time[i+1])) 


   //if(prev_calculated>0)
    //  limit++;   
     
     
  }
//+------------------------------------------------------------------+

int start()
  {
    calc();
    return(0);
  }