Author: Copyright � 2005, MetaQuotes Software Corp.
Speed2_001

This script is designed to measure and visualize the "speed" of price movements relative to average market activity. It works by analyzing the velocity of price changes over a specific timeframe and filtering out insignificant noise to help traders identify meaningful momentum.

Core Logic Overview

The tool operates by looking at the most recent price action and comparing it against a moving average of recent history. Here is the step-by-step breakdown of how it processes data:

1. Data Collection and Averaging Instead of looking at just one single candle, the script examines a window of the last six price points. It calculates three key averages from this window:

  • The average price movement (in pips).
  • The average trading volume.
  • The average closing prices.

2. Velocity Calculation The script determines "speed" by calculating the difference between the current price and the previous price. However, to ensure this speed is meaningful, it divides that difference by the moving average of the pips. This effectively "normalizes" the data, showing how fast the market is moving relative to its recent normal behavior.

3. Filtering Significant Moves One of the primary functions of this script is its ability to ignore "market noise." It uses specific thresholds (minimum and maximum pip values) that you can customize.

  • If a price move is too small (below your minimum setting), the script treats it as insignificant and sets the value to zero.
  • If a move is excessively large (above your maximum setting), it may also be filtered out to avoid reacting to extreme outliers or "flash" spikes that don't represent sustained momentum.

4. Cumulative Tracking The logic includes a toggle for cumulative calculation. When enabled, the script tracks the running total of these speed values. This allows you to see the progression of momentum over time rather than just isolated snapshots of speed.

Visual Output

The result is plotted in a separate window at the bottom of your trading chart. It provides three distinct lines (buffers) that react differently based on your chosen pip thresholds. By watching these lines, you can visually identify periods where the market is accelerating or decelerating with enough strength to be considered significant by your specific criteria.

Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
Speed2_001
//+------------------------------------------------------------------+
//|                                                 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 vit1=(close0-close1)/(vol0-vol1);  
      double vit2=(close1-close2)/(vol1-vol2);  
      //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