iAvgVol
Download scriptThis tool is designed to provide traders with a visual representation of trading volume dynamics by comparing current market activity against historical averages. By analyzing these two distinct data points simultaneously, it helps identify whether the current trading momentum is exceptionally high or low relative to normal conditions.
Core Functionality
The script operates by generating two primary visual lines on a separate window below your main price chart:
- Current Volume: This line tracks the actual amount of trading activity occurring during each specific candle. It provides a raw look at how much "action" is happening in the market at any given moment.
- Average Volume: This represents a smoothed calculation of trading activity over a user-defined timeframe (the period). Instead of looking at just one bar, it looks back at a set number of previous bars to calculate a "normal" baseline for volume.
How the Logic Works
The script follows a straightforward mathematical process to provide these insights:
- Data Collection: The tool scans every candle on your chart starting from the most recent.
- Current Value Mapping: It first identifies the specific volume of the current bar and plots it as the primary data point.
- Moving Average Calculation: To determine the "average," the script looks back at a specific number of previous bars (defined by the period setting). It adds up the total volume of all those bars and then divides that sum by the number of bars to find the mean.
- Dynamic Comparison: This average is updated constantly as new data arrives, ensuring that the "baseline" moves with the market trends rather than remaining static.
Purpose for the Trader
The goal of this logic is to filter out "noise." While raw volume can be erratic, seeing the Average Volume line allows a trader to distinguish between a routine increase in activity and a significant, high-interest event. When the current volume significantly deviates from the average line, it may signal a shift in market sentiment, such as a breakout or a period of heavy institutional participation.
//+------------------------------------------------------------------+
//| iAvgVol.mq4 |
//| Copyright © 2005, Anri |
//| http://tradestation.narod.ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Anri"
#property link "http://tradestation.narod.ru/"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 WhiteSmoke
//---- input parameters
extern int nPeriod=5;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexLabel(0,"Volume");
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexLabel(1,"Avg Volume");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//---- TODO: add your code here
int i, shift;
double nSum;
//---- initial zero
if(counted_bars<1) // åñëè òåêóùèé áàð ìåíüøå åäèíèöû - íàôèã ñ ïëÿæà, óñòàíàâëèâàåì âñå â íóëè
{
for(i=1;i<=0;i++) {ExtMapBuffer1[Bars-i]=0; ExtMapBuffer2[Bars-i]=0; };
};
//---- âû÷èñëåíèÿ
for(shift=Bars-1;shift>=0;shift--) {
nSum=Volume[shift];
ExtMapBuffer1[shift]=nSum;
if ((nPeriod>0)&&(shift<(Bars-1-nPeriod))) {
for(i=nPeriod-1;i>=1;i--) {
nSum=nSum+ExtMapBuffer1[shift+i];
};
nSum=nSum/nPeriod;
};
ExtMapBuffer2[shift]=nSum;
};
return(0);
}
//+------------------------------------------------------------------+
Comments