Expected_Volumes__v2
Download scriptThis tool is designed to provide traders with a clear visual representation of "Expected Volume" by analyzing historical trading activity. Instead of simply showing you how much volume occurred in the immediate past, it uses a statistical approach to calculate an average baseline based on recurring patterns.
How the Logic Works
The script functions by looking back at your trading history to identify specific behaviors at the same time of day. Here is a breakdown of the process it follows:
- Time-Based Correlation: The tool identifies the specific hour of the current candle and looks back through previous days to find the exact same hour. For example, if it is currently 2:00 PM, it seeks out the 2:00 PM data points from previous sessions.
- Data Collection (The "History Steps"): The script doesn't just look at one day; it scans back through a set number of historical observations (defined by your settings). This allows it to build a broader picture of what "normal" activity looks like for that specific time of day.
- Volume Averaging: As the script scans through these historical matches, it gathers the trading volume for each corresponding period. It then calculates the average of these volumes across all those historical steps.
- The Result: The final output is a histogram that represents the "Expected Volume." By comparing this value to the real-time volume you see on your chart, you can better understand whether the current market activity is typical for this time of day or if there is an unusual surge (or lack thereof) in trading participation.
Key Benefit
By normalizing the data this way, the tool helps filter out the "noise" of daily fluctuations. It provides a smoothed baseline, allowing you to see what the expected level of market activity should be based on historical trends, rather than just reacting to the immediate price movement.
//+------------------------------------------------------------------+
//| 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 1
#property indicator_color1 clrBlue
//---- input parameters
extern int hist_steps=100; // Number of observations
extern int span=1; // Days to step back each time
//---- buffers
double ExtMapBuffer1[];
int sum;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicators
SetIndexStyle(0, DRAW_HISTOGRAM);
SetIndexBuffer(0,ExtMapBuffer1);
//----
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;
if(counted_bars==0) rest--;
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((rest+k)>=Bars) break;
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;
rest--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments