
#property indicator_separate_window
#property indicator_buffers 6

#property indicator_color1 White
#property indicator_color2 Black

#property indicator_width1 2     
#property indicator_width2 2     

extern int dif=1;
double mov[],trend[],wave[],up[],dn[],vol[];
int firstrun;

int init() {

IndicatorBuffers(6);

SetIndexBuffer(0,up);
SetIndexBuffer(1,dn);
SetIndexBuffer(2,mov);
SetIndexBuffer(3,trend);
SetIndexBuffer(4,wave);
SetIndexBuffer(5,vol);

SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID);
SetIndexStyle(2,DRAW_NONE);
SetIndexStyle(3,DRAW_NONE);
SetIndexStyle(4,DRAW_NONE);
SetIndexStyle(5,DRAW_NONE);

   return(0); }
 
//+------------------------------------------------------------------+
int start() {

   int limit, i;
   int counted_bars=IndicatorCounted();
   //---
   if(counted_bars<0) return(-1);
   //----
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   
mov[limit]=0;
trend[limit]=0;
wave[limit]=0;
vol[limit]=0;
up[limit]=0;
dn[limit]=0;

for(i=limit-1; i>=0; i--) {

if (Close[i]-Close[i+1]>0) mov[i]=1;
if (Close[i]-Close[i+1]==0) mov[i]=0;
if (Close[i]-Close[i+1]<0) mov[i]=-1; 

if ((mov[i]!=0) && (mov[i]!=mov[i+1])) {trend[i]=mov[i];} else {trend[i]=trend[i+1];} 

if ((trend[i]!=wave[i+1]) && (MathAbs(Close[i]-Close[i+1])*10000>=dif)) {wave[i]=trend[i];} else {wave[i]=wave[i+1];}    

if (wave[i]==wave[i+1]) {vol[i]=vol[i+1]+Volume[i];} else {vol[i]=Volume[i];}

if (wave[i]==1) {up[i]=vol[i]; dn[i]=0;}
if (wave[i]==-1) {dn[i]=vol[i]; up[i]=0;}
   
   }


return(0); 
}