CDRW Volume v1.1
Download scriptThis custom trading indicator is designed to provide a visual representation of market volume dynamics by analyzing how trading activity changes over time. Rather than just showing a raw total of volume, it categorizes the flow of trade intensity into three distinct states—Expanding, Contracting, and Neutral—while providing a smoothed average for broader context.
Core Logic Overview
The tool works by comparing the volume of the current price bar against the volumes of the two preceding bars. By looking at this three-bar sequence, the script determines the "momentum" of the trading activity:
- Expanding Volume (Growth): If the current volume is higher than both of the previous two bars, the indicator identifies this as an expansion in activity. This suggests increasing participation or interest in the market move.
- Contracting Volume (Decrease): If the current volume is lower than both of the previous two bars, the indicator marks this as a contraction. This can signal a loss of momentum or a cooling off in trading intensity.
- Neutral Volume: When the current volume does not clearly exceed or fall below the previous two bars (for instance, if it is sandwiched between them or remains steady), it is categorized as neutral activity.
Visual Components and Features
The indicator displays these insights in a dedicated window separate from the main price chart, utilizing several visual layers to help traders distinguish between different market states:
- Histogram Bars: The primary data is shown as a histogram. You will see different colors representing the expansion, contraction, and neutral states identified by the logic above. This allows for a quick at-a-glance assessment of whether the "energy" behind price movements is increasing or decreasing.
- Moving Average Line: In addition to the specific bar-by-bar volume analysis, the script calculates a Moving Average based on a user-defined period. This line smooths out the total volume data over a set number of bars, helping traders identify the long-term trend of trading activity rather than just short-term fluctuations.
- Customizable Depth: The tool includes settings that allow users to define how many historical bars they want to view on the screen at one time, ensuring the visual workspace remains clean and relevant to the user's preferred timeframe.
By combining these elements, the indicator serves as a specialized diagnostic tool for measuring "market heartbeat," helping traders see whether the volume supporting a price move is strengthening, weakening, or remaining stable.
#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