Expected Volumes
Download scriptThe Expected Volumes indicator is designed to help traders visualize and analyze trading activity by comparing current market behavior against historical averages. By distilling large amounts of past data into a readable format, it provides a benchmark for what "normal" trading volume looks like at specific times of the day.
Core Logic Overview
The script operates by performing a sophisticated look-back analysis to establish a baseline for liquidity. Instead of simply showing you how much volume occurred in the last hour, it looks back through hundreds of previous sessions to determine what the typical volume should be for that specific time slot.
How the Analysis Works
- Historical Benchmarking: The tool examines a set number of historical observations (defined by the user) to build a statistical profile of market activity.
- Time-Specific Matching: To ensure accuracy, the logic doesn't just average all past data. It identifies the specific hour of the current candle and then seeks out the corresponding hours from previous days. This means it calculates a "typical" volume for a Monday morning based on other Monday mornings, rather than blending different times of day together.
- Averaging and Normalization: Once it gathers these historical data points for the specific time slot, it calculates an average. This resulting figure represents the "Expected Volume."
Visual Representation
The indicator displays this information in a separate window on your chart using two distinct visual elements:
- The Expected Volume (Histogram): Shown as a blue histogram, this represents the calculated historical average. It acts as your baseline—the "expected" level of activity based on previous history.
- Current Volume (Line): Shown as a red line, this tracks the actual volume occurring in real-time.
Practical Application for Traders
By viewing these two elements side-by-side, you can instantly identify anomalies in market behavior:
- If the Red Line (Current) is significantly higher than the Blue Histogram (Expected), it indicates unusually high activity or a surge in interest for that specific time of day.
- If the Red Line is lower than the Blue Histogram, it suggests a period of lower-than-normal liquidity or a "quiet" market phase.
Essentially, this tool removes the guesswork from volume analysis by providing a historical context, allowing you to see whether current market participation is typical or extraordinary.
//+------------------------------------------------------------------+
//| Expected Volumes.mq4 |
//| Copyright © 2007, Amir Aliev |
//| http://finmat.blogspot.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Amir Aliev"
#property link "http://finmat.blogspot.com"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2
//---- input parameters
extern int hist_steps = 100; // Number of observations
extern int span = 1; // Days to step back each time
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
int sum;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicators
SetIndexStyle(0, DRAW_HISTOGRAM);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1, DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
//----
short_name = "Expected volumes(" + hist_steps + ")";
IndicatorShortName(short_name);
SetIndexLabel(0, short_name);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
int rest = Bars - counted_bars;
int j, k, u;
//----
while(rest >= 0)
{
if(Bars - rest < span * 23 * hist_steps)
{
ExtMapBuffer1[rest] = 0;
rest--;
continue;
}
sum = 0;
j = 0;
k = 0;
u = 0;
while(j < hist_steps && k < Bars)
{
if(TimeHour(Time[rest+k]) == TimeHour(Time[rest]))
{
u++;
if(u == span)
{
u = 0;
j++;
sum += Volume[rest + k];
}
k += 23;
}
k++;
}
ExtMapBuffer1[rest] = sum / hist_steps;
ExtMapBuffer2[rest] = Volume[rest];
rest--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments