Author: Copyright � 2005, MetaQuotes Software Corp.
Speed

This script is a custom technical analysis indicator designed to measure the "speed" or momentum of price movements by comparing price changes against trading volume. Instead of looking at price in isolation, it evaluates how much effort (volume) is being exerted to achieve a specific result in price movement.

Core Logic Overview

The indicator operates by analyzing the relationship between consecutive price bars and their associated trading volumes. It seeks to identify significant movements that meet specific criteria, filtering out minor market "noise."

Key Components of the Calculation

1. Data Sampling and Averaging To establish a baseline for what constitutes "normal" market activity, the script looks at a window of the 6 most recent bars. It calculates the average price (in pips), average volume, and average closing price. These averages serve as the benchmark against which current market action is measured.

2. Movement Filtering The indicator does not react to every minor tick in the market. It uses user-defined thresholds (minimum and maximum "pips") to determine if a price move is significant enough to be recorded. If a price change falls outside these boundaries, the script ignores that data point.

3. Speed Calculation Formula For the movements that pass the filters, the script calculates a velocity metric using two primary factors:

  • Price Velocity: The difference between the current price change and the average price change over the recent period.
  • Volume Intensity: The difference between the current volume and the average volume.

By dividing the price velocity by the volume intensity, the script derives a "Speed" value. Essentially, it calculates how much price movement is achieved per unit of volume. High values suggest efficient movement (large price changes with relatively low effort), while lower values might suggest "heavy" movement (small price changes requiring high volume).

4. Cumulative vs. Instantaneous View The script includes a toggle for "Cumulative" logic.

  • When enabled, it creates a running total of the speed values, showing how the momentum builds over a period of time.
  • When disabled, it focuses on the immediate, instantaneous speed of the current price action.

Visual Representation

The script outputs three distinct data lines on a separate window below the main price chart:

  • Line 1 (LightSeaGreen): Represents the primary speed calculation based on the first set of user-defined pip boundaries.
  • Line 2 (Red): Represents an alternative speed calculation using a second, tighter set of pip boundaries.
  • Line 3 (Lime): This line is included in the structure but is primarily reserved for different logic variations or secondary calculations.

Summary for Traders

This tool helps traders identify "fast" moves where the market is moving aggressively with conviction. By observing these lines, a trader can see whether the current price trend is gaining momentum efficiently or if it is becoming sluggish as volume requirements increase to move the price further.

Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
Speed
//+------------------------------------------------------------------+
//|                                                 Speed.mq4        |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 LightSeaGreen
#property indicator_color2 Red
#property indicator_color3 Lime

extern bool cumulat=true;
extern int pips_min=10;
extern int pips_max=300;
extern int pips_min1=10;
extern int pips_max1=20;
extern int pips_min2=10;
extern int pips_max2=30;

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorShortName("Speed ((C0-C1)/Cm) / ((V0-V1)/Vm)");
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);   
   SetIndexEmptyValue(2,0);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Accumulation/Distribution                                        |
//+------------------------------------------------------------------+
int start()
  {
   int i,n,Bars1,counted_bars=IndicatorCounted();
   RefreshRates();
      double high0 =0;
      double low0  =0;
      double open0 =0;
      double close0=0;
      double pips0=0;
      double vol0=0;
      
      double high1 =0;
      double low1  =0;
      double open1 =0;
      double close1=0;
      double pips1=0;
      double vol1=0;
      
      double high2 =0;
      double low2  =0;
      double open2 =0;
      double close2=0;
      double pips2=0;
      double vol2=0;     

      double high3 =0;
      double low3  =0;
      double open3 =0;
      double close3=0;
      double pips3=0;
      double vol3=0;
      
      double high4 =0;
      double low4  =0;
      double open4 =0;
      double close4=0;
      double pips4=0;
      double vol4=0;
      
      double high5 =0;
      double low5  =0;
      double open5 =0;
      double close5=0;
      double pips5=0;
      double vol5=0;    

      double close_med =0;
      double vol_med=0;
      double pips_med=0;      
      double vit1=0;   
      double vit2=0;         
//----
   //i=0;
   //n=Bars-counted_bars-1;
   //while(i<=n)
   Bars1=Bars/2;
   i=Bars1;//Bars-counted_bars-1;
   while(i>=0)   
   {
      high0 =High[i];
      low0  =Low[i];
      open0 =Open[i];
      close0=Close[i];
      pips0=close0/Point;
      vol0=Volume[i];
      
      high1 =High[i+1];
      low1  =Low[i+1];
      open1 =Open[i+1];
      close1=Close[i+1];
      pips1=close1/Point;
      vol1=Volume[i+1];
      
      high2 =High[i+2];
      low2  =Low[i+2];
      open2 =Open[i+2];
      close2=Close[i+2];
      pips2=close2/Point;
      vol2=Volume[i+2];     

      high3 =High[i+3];
      low3  =Low[i+3];
      open3 =Open[i+3];
      close3=Close[i+3];
      pips3=close0/Point;
      vol3=Volume[i+3];
      
      high4 =High[i+4];
      low4  =Low[i+4];
      open4 =Open[i+4];
      close4=Close[i+4];
      pips4=close1/Point;
      vol4=Volume[i+4];
      
      high5 =High[i+5];
      low5  =Low[i+5];
      open5 =Open[i+5];
      close5=Close[i+5];
      pips5=close5/Point;
      vol5=Volume[i+5];    

      close_med = (close0+close1+close2+close3+close4+close5)/6;
      vol_med= (vol0+vol1+vol2+vol3+vol4+vol5)/6;
      pips_med= (pips0+pips1+pips2+pips3+pips4+pips5)/6;      
      
      if (close_med==0) close_med=1;
      if (vol_med==0) vol_med=1;
      if (pips_med==0) pips_med=1;
      
      if (((pips0-pips1)>pips_min) && ((pips0-pips1)<pips_max) ) 
      {
        double x1=((vol0-vol1)/vol_med);
        if(x1==0) x1=1;
        vit1=((pips0-pips1)/pips_med)/x1;             
        ExtMapBuffer1[i]=vit1;//(close0-close1);//vit1;  //(close-low)-(high-close);
      }  
      else
        ExtMapBuffer1[i]=0;        

      if (((pips0-pips1)>pips_min1) && ((pips0-pips1)<pips_max1) ) 
      {
        double x2=((vol0-vol1)/vol_med);
        if(x2==0)x2=1;
        vit1=((pips0-pips1)/pips_med)/x2;             
        ExtMapBuffer2[i]=vit1;//(close0-close1);//vit1;  //(close-low)-(high-close);
      }  
      else
        ExtMapBuffer2[i]=0;      
 /*       
      if (((pips0-pips1)>pips_min2) && ((pips0-pips1)<pips_max2) ) 
      {
        vit1=((pips0-pips1)/pips_med)/((vol0-vol1)/vol_med);             
        ExtMapBuffer3[i]=vit1;//(close0-close1);//vit1;  //(close-low)-(high-close);
      }  
      else
        ExtMapBuffer3[i]=0;                 
      
 */   double x3=(vol1-vol2);
      if(x3==0)x3=1 ; 
      vit2=(pips1-pips2)/x3;  
      //ExtMapBuffer1[i]=ExtMapBuffer1[i+1]+Volume[i];             
      //ExtMapBuffer1[i]=vit1;  //(close-low)-(high-close);
      /*
      if(ExtMapBuffer1[i]!=0)
      {
         double diff=high-low;
         if(0==diff)
            ExtMapBuffer1[i]=0;
         else
         {
            ExtMapBuffer1[i]/=diff;
            ExtMapBuffer1[i]*=Volume[i];
         }
      }*/
      if((i<Bars1-1) && cumulat) 
      {
        ExtMapBuffer1[i]-=ExtMapBuffer1[i+1];
        ExtMapBuffer2[i]-=ExtMapBuffer2[i+1];
        //ExtMapBuffer3[i]-=ExtMapBuffer3[i+1];
      }  
      
      
      i--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments