CDRW Volume v1.1

Author:
CDRW Volume v1.1
Price Data Components
Series array that contains tick volumes of each bar
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
CDRW Volume v1.1

#property copyright ""
#property link      ""

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 Yellow
#property indicator_color4 Maroon
#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 3
#property indicator_width4 2

extern string  Note = " MumberOfBars = 0  Displays all Bars";
extern int     NumberOfBars = 500;
extern int     MAPeriod = 100;

double up[],dn[],flat[],v4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
      SetIndexBuffer(0,up);
      SetIndexStyle(0,DRAW_HISTOGRAM,0,3);
      SetIndexLabel(0,"Expanding Volume");
      
      SetIndexBuffer(1,dn);
      SetIndexStyle(1,DRAW_HISTOGRAM,0,3);
      SetIndexLabel(1,"Contracting Volume");
      
      SetIndexBuffer(2,flat);
      SetIndexStyle(2,DRAW_HISTOGRAM,0,3);
      SetIndexLabel(2,"Neutral Volume");

      SetIndexBuffer(3,v4);
      SetIndexStyle(3,DRAW_LINE);
      SetIndexLabel(3,"MovingAverage("+MAPeriod+")");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
   double v0,v1,v2, tempv;
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   if ( NumberOfBars == 0 ) 
      NumberOfBars = Bars-counted_bars;
   limit=NumberOfBars; //Bars-counted_bars;

   for(int i=0; i<limit; i++)   
      {
         up[i] = 0; dn[i] = 0; v4[i]=0;tempv=0;
       
         v0 = iVolume(NULL,0,i);
         v1 = iVolume(NULL,0,i+1);
         v2 = iVolume(NULL,0,i+2);
         
         flat[i] = v0;
         
         if ( v0<v1 && v0<v2 )
            {
               dn[i] = v0;
               flat[i] = 0;
            }   
         if ( v0>v1 && v0>v2 )
            {
               up[i] = v0;
               flat[i] = 0;
            }   
         for ( int n=i;n<i+MAPeriod;n++ )
            {
               tempv= Volume[n] + tempv; 
            } 
          v4[i] = tempv/MAPeriod;          
       
      
      }
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments