//+------------------------------------------------------------------+
//------------------------------------------------------------------
#property copyright "www.forex-station.com"
#property link      "www.forex-station.com"
//------------------------------------------------------------------

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1  clrLimeGreen
#property indicator_color2  clrBrown
#property indicator_color3  clrDarkGreen
#property indicator_color4  clrMaroon
#property indicator_width1  5
#property indicator_width2  5
#property indicator_width3  3
#property indicator_width4  3
#property strict

//
//
//

input int             Tenkan                = 9;       // Tenkan Period
input int             Kijun                 = 26;      // Kijun Period
input int             Senkou                = 52;      // Senkou Period
input bool            UseKijunShift         = true;    // Use Kijun shift
  

double spA1[],spB1[],spA2[],spB2[];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int OnInit()
{
   SetIndexBuffer(0,spA1,INDICATOR_DATA); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexLabel(0,"Kumo cloud");   
   SetIndexBuffer(1,spB1,INDICATOR_DATA); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexLabel(1,"Kumo cloud"); 
   SetIndexBuffer(2,spA2,INDICATOR_DATA); SetIndexStyle(2,DRAW_LINE);      SetIndexLabel(2,"Senkou Span A");
   SetIndexBuffer(3,spB2,INDICATOR_DATA); SetIndexStyle(3,DRAW_LINE);      SetIndexLabel(3,"Senkou Span B");  
   
   SetIndexShift(0,UseKijunShift ? Kijun : 0); 
   SetIndexShift(1,UseKijunShift ? Kijun : 0);
   SetIndexShift(2,UseKijunShift ? Kijun : 0);
   SetIndexShift(3,UseKijunShift ? Kijun : 0); 
        
   IndicatorSetString(INDICATOR_SHORTNAME,"Kumo cloud");
return(INIT_SUCCEEDED);
}  

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,const int prev_calculated,const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   int i,limit=fmin(rates_total-prev_calculated+1,rates_total-1);
     
   //
   //
   //
   
   for(i=limit; i>=0; i--)
   {
      double tlo =  low[ArrayMinimum( low,Tenkan,i)];
      double thi = high[ArrayMaximum(high,Tenkan,i)];
      double ts  = ((thi+tlo)!=0) ? (thi+tlo)*0.5 : 0;
         
      double klo =  low[ArrayMinimum( low,Kijun,i)];
      double khi = high[ArrayMaximum(high,Kijun,i)];
      double ks  = ((khi+klo)!=0) ? (khi+klo)*0.5 : 0;
        
      double slo =  low[ArrayMinimum( low,Senkou,i)];
      double shi = high[ArrayMaximum(high,Senkou,i)];
         spA1[i] = (ks+ts)*0.5;
         spA2[i] = (ks+ts)*0.5;
         spB1[i] = (shi+slo)*0.5; 
         spB2[i] = (shi+slo)*0.5; 
     }
return(rates_total);
}    


  

