//+------------------------------------------------------------------+
//|  AO+                                                     ACC.mq4 |
//+------------------------------------------------------------------+
//2008fxtsd   ki

#property  copyright ""
#property  link      ""


#property  indicator_separate_window
#property  indicator_buffers 4
#property  indicator_color1  LimeGreen
#property  indicator_color2  Green
#property  indicator_color3  Red
#property  indicator_color4  Crimson

#property indicator_width1 2
#property indicator_width3 2


extern bool ACAOmode_AC = true;

//---- 

double     Buffer1[];
double     Buffer2[];
double     Buffer3[];
double     Buffer4[];
double     Buffer5[];
double     Buffer6[];

//+-----------------------


int init()
  {

   IndicatorBuffers(6);


   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexStyle(3,DRAW_HISTOGRAM);

   SetIndexDrawBegin(0,38);
   SetIndexDrawBegin(1,38);
   SetIndexDrawBegin(2,38);
   SetIndexDrawBegin(3,38);

//----

   SetIndexBuffer(0,Buffer1);
   SetIndexBuffer(1,Buffer2);
   SetIndexBuffer(2,Buffer3);
   SetIndexBuffer(3,Buffer4);
   SetIndexBuffer(4,Buffer5);
   SetIndexBuffer(5,Buffer6);

   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
   SetIndexLabel(3,NULL);
   SetIndexLabel(4,NULL);


   if (ACAOmode_AC)string mode = "AC ";   else mode = "AO ";
   
   IndicatorShortName("ACAO mode "+mode);


   return(0);
  }


//+---------------------------------------

int start()
  {
   double prev,current;
 
   int    i,limit,counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
 
   limit= Bars-counted_bars;

   
   for(i=limit; i>=0; i--)
  
      Buffer5[i]=iMA(NULL,0,5,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(NULL,0,34,0,MODE_SMA,PRICE_MEDIAN,i);


   for(i=limit; i>=0; i--)
   {
      Buffer6[i]=iMAOnArray(Buffer5,0,5,0,MODE_SMA,i);
  
    
      if (ACAOmode_AC) {current= Buffer5[i]-Buffer6[i];   prev=Buffer5[i+1]-Buffer6[i+1];}
      else             {current= Buffer5[i];              prev=Buffer5[i+1];}



            Buffer1 [i]=0.0;        Buffer2[i]=0.0;       Buffer3[i]=0.0;        Buffer4[i]=0.0;


      if(current>0) 
      { 
         if(current>prev)  {   
            Buffer1[i]=current;     Buffer2[i]=0.0;        Buffer3[i]=0.0;       Buffer4[i]=0.0;
                           }
          else             {
            Buffer1[i]=0.0;         Buffer2[i]=current;    Buffer3[i]=0.0;       Buffer4[i]=0.0;
                           }
      }
      else 
      {    
            if(current>prev)  {
            Buffer1[i]=0.0;         Buffer2[i]=0.0;         Buffer3[i]=current;   Buffer4[i]=0.0;
                              }
            else              {
            Buffer1[i]=0.0;         Buffer2[i]=0.0;         Buffer3[i]=0.0;       Buffer4[i]=current;
                              }
      }

   }

   return(0);
 }
//+------------------------------------------------------------------+

