Author: Copyright � 2005, DriverDan
VSI_v2

This script is a specialized technical analysis tool designed for the MetaTrader platform to help traders visualize trading activity intensity more accurately. While standard volume indicators often simply show the total amount of trading during a specific timeframe (like an hour or a day), this tool provides a more granular look by calculating the Volume Per Second.

Core Logic and Functionality

1. Normalizing Volume for Consistency The primary logic of this script is to "normalize" volume data. Because different chart timeframes (e.g., comparing a 15-minute chart to a 4-hour chart) naturally have different total volumes, it can be difficult to compare market activity across them directly. This script solves that by breaking down the volume into a per-second rate. By calculating how much trading occurs every second, you can maintain a consistent perspective on market speed regardless of which timeframe you are currently viewing.

2. Real-Time vs. Historical Calculation The script handles data differently depending on whether it is looking at the current "live" candle or past historical candles:

  • Live Data: For the candle currently forming, the script calculates the volume divided by the elapsed time since that candle started. This provides a real-time "speedometer" of market activity.
  • Historical Data: For completed candles, it takes the total volume of that period and divides it by the total duration of that period in seconds.

3. Moving Average Smoothing To make the volume data easier to read and to filter out "noise," the script includes a built-in Moving Average (MA). This smooths out the jagged spikes in the per-second volume data, creating a trend line that helps traders identify whether trading intensity is increasing, decreasing, or stabilizing over time.

4. Customization Options The tool offers specific toggles to adjust how the information is displayed:

  • Smoothing Type: Users can choose different types of moving averages (such as Simple, Exponential, or Weighted) to change how the data is smoothed.
  • Comparison Mode: There is an option to switch between "Volume Per Second" (best for comparing across different timeframes) and "Volume Per Period" (which displays the total volume relative only to the specific timeframe currently on your screen).

Summary of Use

Ultimately, this script is designed to provide a more accurate "heartbeat" of the market. By converting raw volume into a standardized per-second rate and smoothing it with a moving average, it allows traders to see exactly how fast the market is moving at any given moment, providing a clearer picture of liquidity and participation.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
VSI_v2
//+------------------------------------------------------------------+
//|                                                                  |
//|                       "Copyright © 2005, DriverDan"              |
//|                             superfunman2000@yahoo.com            |
//+------------------------------------------------------------------+
/*
 * Filename:    VSI.mq4
 * Author:      DriverDan
 * Date:        Oct 20, 2005
 *
 * Description: Indicator that calculates volume per second (or period) and the corresponding MA.
 *              Uses volume per second since it will be uniform for all chart periods.
 *              Indicator seems to work best on 15m to 4h charts. IMHO, 1m and 5m periods are
 *              too short for valid results and 1d+ will show low periods for partial days on MT4.
 *
 * Version:     1.0
 *              Initial release
 */

#property copyright         "Copyright © 2005, DriverDan"
#property link              "superfunman2000@yahoo.com"
//----
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_buffers 2
#property indicator_color1  DodgerBlue
#property indicator_color2  Red
//----
#define    SECINMIN         60  //Number of seconds in a minute
//----
extern int vsiMAPeriod   =7;  //Period for the moving average.
extern int vsiMAType     =1;  //Moving average type. 0 = SMA, 1 = EMA, 2 = SMMA, 3 = LWMA
extern int showPerPeriod =0;  //0 = volume per second, 1 = volume per chart period
                                /* Volume per second allows you to compare values for different
                                   chart periods. Otherwise the values it will show will only be
                                   valid for the chart period you are viewing. The graph will
                                   look exactly the same but the values will be different. */
double vsiBuffer[];
double vsiMABuffer[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
  int init() 
  {
   string vsiTitle="VSI(" + vsiMAPeriod + ")";
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(0, vsiBuffer);
   SetIndexBuffer(1, vsiMABuffer);
   IndicatorShortName(vsiTitle);
   SetIndexLabel(0, vsiTitle);
   SetIndexLabel(1, "vsiMA(" + vsiMAPeriod + ")");
   SetIndexDrawBegin(1, vsiMAPeriod);
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
  int start() 
  {
   int i, limit, timeDiff;
   int counted_bars=IndicatorCounted();
     if(counted_bars>=0) 
     {
      //If counted bars is greater than zero we must subtract 1 so we get in the right position
        if(counted_bars > 0) 
        {
         counted_bars--;
        }
      //Only count bars we haven't already drawn
      limit=Bars - counted_bars;
//----
        for(i=0; i < limit; i++) 
        {
         //Difference between the current time and the bar start
         timeDiff=CurTime() - Time[i];
         //If we are in the current bar and the tick doesn't fall exactly on the '00:00' min & sec
           if(i==0 && timeDiff > 0) 
           {
            vsiBuffer[i]=Volume[i]/timeDiff;
            }
             else 
            {
            //Otherwise calculate the total bar volume divided by the total bar seconds
            vsiBuffer[i]=Volume[i]/(Time[i - 1] - Time[i]);
           }
           if(showPerPeriod==1) 
           {
            vsiBuffer[i]=vsiBuffer[i] * Period() * SECINMIN;
           }
        }
      //Fill the moving average buffer
        for(i=0; i < limit; i++) 
        {
         vsiMABuffer[i]=iMAOnArray(vsiBuffer, Bars, vsiMAPeriod, 0, vsiMAType, i);
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+

Comments