Expected_Volumes__v1

Download script
Expected_Volumes__v1

This tool is designed to help traders visualize and understand average trading activity by calculating "Expected Volumes" across historical data. Instead of simply showing you the raw volume of a single moment in time, it filters out the noise to provide a more structured view of how much trading typically occurs at specific times of the day.

How the Logic Works

The script operates by looking backward through your trading history and analyzing patterns based on two primary factors: the time of day and a specific historical window. Here is the breakdown of its internal process:

Time-Based Filtering The tool identifies specific hours within a trading day. It scans the history to find segments that match the current hour of the day. This ensures that it is comparing "apples to apples"—for example, comparing 10:00 AM volume today against 10:00 AM volume from previous days, rather than mixing it with midday or evening data.

Data Sampling Rather than adding up every single price movement, the script uses a specific "step" logic. It looks back through history and selects data points at regular intervals. This prevents the calculation from being skewed by a single, massive outlier (like one giant trade) and instead builds a more reliable average of steady market participation.

The Averaging Process Once the tool identifies the relevant historical data points for a specific time slot:

  1. It gathers the volume from those identified points across a set number of previous observations (determined by your settings).
  2. It calculates the sum of these volumes.
  3. It divides that sum by the total number of observations to produce a single average value.

What This Means for You

The result is a visual histogram that represents the "expected" amount of activity. By looking at this indicator, you can better understand whether the current volume you are seeing in the market is normal for that specific time of day or if it represents an unusual surge or drop in interest. It effectively creates a "baseline" of market activity, allowing you to distinguish between standard daily fluctuations and significant out-of-ordinary movements.

Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
Expected_Volumes__v1
//+------------------------------------------------------------------+
//|                                             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 Blue
//---- 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;
   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;
      rest--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments