Author: Copyright � 2005, MetaQuotes Software Corp.
Speed2

This script is designed to function as a custom technical indicator for trading platforms, specifically aimed at measuring the "speed" or momentum of price movements relative to historical averages. Instead of looking at simple price changes in isolation, it analyzes the velocity of price action by comparing current fluctuations against multi-bar averages.

Core Logic and Methodology

The indicator operates by evaluating the relationship between price movement and volume over a specific look-back period. Here is how the logic flows:

1. Data Collection and Averaging The script examines a window of the most recent 6 bars of market data. For every calculation, it gathers three primary metrics for these bars:

  • Price Levels: The closing prices.
  • Pips: The numerical value of the price movement.
  • Volume: The amount of trading activity occurring.

It then calculates a Median Value for these metrics. This median serves as a "baseline" or "normalization factor," allowing the script to determine if a current move is significant compared to recent history.

2. Movement Filtering (The "Gatekeeper") The script does not display every single price flicker. It uses pre-defined thresholds (minimum and maximum pips) to filter out market noise.

  • If a price change is too small (less than the minimum), it is ignored.
  • If a price change is excessively large (exceeding the maximum), it is also filtered out.
  • Only movements that fall within these specific "active zones" are processed for the final display.

3. Velocity Calculation For movements that pass the filter, the script calculates a velocity score. It takes the difference between the current price movement and the previous one, then divides that difference by the median pips calculated in step one. By dividing by the median, the indicator scales the result—showing you how much "faster" or "slower" the current move is compared to the recent average trend.

4. Cumulative Analysis The script includes a toggle for cumulative logic. When enabled, it performs a subtraction of the previous value from the current value. This creates a smoothed representation of the data, helping to highlight sustained trends in speed rather than just erratic, instantaneous spikes.

Visual Representation

The results are plotted as three separate lines on a separate window below the main price chart:

  • Primary Momentum: The main filtered velocity line (LightSeaGreen).
  • Secondary Momentum: A second filtered velocity line using a different set of sensitivity constraints (Red).
  • Baseline: A third buffer intended for additional comparative data.

In summary, this tool helps traders identify "meaningful" momentum by filtering out minor market noise and highlighting periods where the speed of price movement is significantly deviating from its own recent average.

Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
Speed2
//+------------------------------------------------------------------+
//|                                                 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("Speed2(C0-C1)/Cm");
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);   
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);    
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Accumulation/Distribution                                        |
//+------------------------------------------------------------------+
int start()
  {
   int i,n,Bars1,counted_bars=IndicatorCounted();
   RefreshRates();
//----
   //i=0;
   //n=Bars-counted_bars-1;
   //while(i<=n)
   Bars1=Bars/2;
   i=Bars1;//Bars-counted_bars-1;
   while(i>=0)   
   {
      
      double high0 =High[i];
      double low0  =Low[i];
      double open0 =Open[i];
      double close0=Close[i];
      double pips0=close0/Point;
      double vol0=Volume[i];
      
      double high1 =High[i+1];
      double low1  =Low[i+1];
      double open1 =Open[i+1];
      double close1=Close[i+1];
      double pips1=close1/Point;
      double vol1=Volume[i+1];
      
      double high2 =High[i+2];
      double low2  =Low[i+2];
      double open2 =Open[i+2];
      double close2=Close[i+2];
      double pips2=close2/Point;
      double vol2=Volume[i+2];    

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

      double close_med = (close0+close1+close2+close3+close4+close5)/6;
      double vol_med= (vol0+vol1+vol2+vol3+vol4+vol5)/6;
      double pips_med= (pips0+pips1+pips2+pips3+pips4+pips5)/6;
      
      double x1=(vol0-vol1);
      if(x1==0)x1=1;
      double x2=(vol1-vol2);
      if(x2==0)x2=1;
      double vit1=(close0-close1)/x1;  
      double vit2=(close1-close2)/x2;  
      //ExtMapBuffer1[i]=ExtMapBuffer1[i+1]+Volume[i];  
       if (((pips0-pips1)>pips_min) && ((pips0-pips1)<pips_max) )           
        ExtMapBuffer1[i]=(pips0-pips1)/pips_med;//(close0-close1);//vit1;  //(close-low)-(high-close);
      else
        ExtMapBuffer1[i]=0;  
        
      if (((pips0-pips1)>pips_min1) && ((pips0-pips1)<pips_max1) )           
        ExtMapBuffer2[i]=(pips0-pips1)/pips_med;//(close0-close1);//vit1;  //(close-low)-(high-close);
      else
        ExtMapBuffer2[i]=0;     
 /*       
      if (((pips0-pips1)>pips_min2) && ((pips0-pips2)<pips_max2) )           
        ExtMapBuffer3[i]=(pips0-pips1)/pips_med;//(close0-close1);//vit1;  //(close-low)-(high-close);
      else
        ExtMapBuffer3[i]=0;                   
        */
            /*
      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