Author: Copyright � 2006, Thierry Cl�ment
Vitesse

This script is designed as a technical analysis tool for the MetaTrader platform, specifically intended to measure the "momentum" or velocity of price movements. Rather than simply looking at where the price is currently sitting, it focuses on how fast the average price is changing over time.

Core Logic Overview

The logic operates in three distinct layers to filter out market noise and provide a smoothed representation of market speed:

1. Establishing the Baseline (Moving Average) The script first identifies the general trend by calculating a Simple Moving Average (SMA) based on a specific number of previous closing prices (defaulting to 50). This creates a smooth line that represents the "middle ground" of the price action, ignoring minor flickers or temporary spikes.

2. Measuring the Rate of Change (The Indicator) Once the average is established, the script compares the current average value against the previous one. By calculating the percentage difference between these two points, it determines the immediate velocity of the trend.

  • If the average price stays the same, the velocity is zero.
  • If the average price moves up or down, the script calculates exactly how much it shifted relative to its previous position.

3. Smoothing the Velocity (The Final "Vitesse") Because raw percentage changes can be very jumpy and erratic, the script performs one final calculation. It takes the velocity data from the previous step and applies a second moving average (defaulting to 10 periods). This "smooths out" the results, providing the user with a stable line that shows the underlying speed of the market trend without the distraction of constant fluctuations.

Key Functional Behaviors

  • Timeframe Adaptation: The script includes built-in logic to adjust its calculations based on the timeframe you are viewing (e.g., minutes, hours, or days). This ensures that the "shift" in data remains consistent regardless of whether you are looking at a high-frequency chart or a long-term daily chart.
  • Visual Output: While the script performs three internal calculations, it is designed to display the final smoothed "Vitesse" (Velocity) as a visual line on your chart, allowing for easier interpretation of market momentum at a glance.
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
17 Views
0 Downloads
0 Favorites
Vitesse
//+------------------------------------------------------------------+
//|                                                      Vitesse.mq4 |
//|                            Copyright © 2007, GwadaTradeBoy Corp. |
//|                                            racooni_1975@yahoo.fr |
//+------------------------------------------------------------------+
//|                                          Author: Thierry Clément |
//|                                 MQ4 Conversion: Ignace BIENVILLE |
//|                                            racooni_1975@yahoo.fr |
//+------------------------------------------------------------------+
/*[[
REM Calcul de la Vitesse
MaMoyenne = Average[50](Close)
IF MaMoyenne[1]<> 0 THEN
   Indicateur = 100*(MaMoyenne - MaMoyenne[1]) / MaMoyenne[1]
ELSE
   Indicateur = 0
ENDIF
Vitesse = Average[10](Indicateur)
Return Vitesse
+------------------------------------------------------------------+
Clément, Thierry (CB). 
Le guide complet de l'analyse technique pour la gestion de vos 
portefeuilles boursiers 3e édition.
Maxima, 2006.
ISBN 2 84 001 480-7
Page 122
]]*/
#property copyright "Copyright © 2007, GwadaTradeBoy Corp."
#property link      "racooni_1975@yahoo.fr"
#property copyright "Copyright © 2006, Thierry Clément"
#property link      "thierry-clement@maxima.fr"

#property indicator_separate_window
//----Section #property
#property indicator_buffers 3
#property indicator_color1 Black    //LightSeaGreen
#property indicator_color2 Red
#property indicator_color3 LightCoral

//---- 
extern int  MAPeriod = 50;
extern int  VitessePeriod = 10;

//---- Variables
int      nShift;
int      i,j,limit,counted_bars;
//double   vites;

//---- Buffers
double   MaMoyenne[];
double   Indicateur[];
double   Vitesse[];
//ArraySetAsSeries(Indicateur,true);
//int      limitI=ArraySize(Indicateur);

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
   {
//---- indicators
//---- Styles et couleur des Lignes
      SetIndexStyle(0,DRAW_NONE);
      SetIndexBuffer(0,MaMoyenne);
      SetIndexStyle(1,DRAW_NONE);
      SetIndexBuffer(1,Indicateur);
      SetIndexStyle(0,DRAW_LINE);
      SetIndexBuffer(0,Vitesse);
//----       
      switch(Period())
         {
            case     1: nShift = 1;   break;
            case     5: nShift = 3;   break;
            case    15: nShift = 5;   break;
            case    30: nShift = 10;  break;
            case    60: nShift = 15;  break;
            case   240: nShift = 20;  break;
            case  1440: nShift = 80;  break;
            case 10080: nShift = 100; break;
            case 43200: nShift = 200; break;
         }
//----
      return(0);
   }

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
   {
//----
   
//----
      return(0);
   }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
   {
      counted_bars = IndicatorCounted();
//----
      if(counted_bars < 0) 
         return(-1);
      if(counted_bars > 0) 
         counted_bars--;
//---- initial zero
      if(counted_bars < 1)
         for(i = 1; i <= MAPeriod; i++)
            {
               MaMoyenne[Bars - i] = EMPTY_VALUE;
               Indicateur[Bars - i] = EMPTY_VALUE;
               Vitesse[Bars - i] = EMPTY_VALUE;
            }
//----
      limit = Bars - counted_bars;
      for(i = 0; i < limit; i++)
         {
            if (Period() >= 1440)
               MaMoyenne[i] = iMA(NULL,0,MAPeriod,0,MODE_SMA,PRICE_CLOSE,i);
            else
               MaMoyenne[i] = iMA(NULL,PERIOD_D1,MAPeriod,0,MODE_SMA,PRICE_CLOSE,i);
            if (MaMoyenne[i+1] != 0) // <> Diferent de
               Indicateur[i] = 100 * ((MaMoyenne[i] - MaMoyenne[i+1]) / MaMoyenne[i+1]);
            else
               Indicateur[i] = 0;
//            vites = iMAOnArray(Indicateur,0,VitessePeriod,0,MODE_SMA,i);  //( Indicateur)
//            Vitesse[i] = vites;
//  iMAOnArray( double array[], int total, int period, int ma_shift, int ma_method, int shift) 
            Vitesse[i] = iMAOnArray(Indicateur,0,VitessePeriod,0,MODE_SMA,i);  //( Indicateur)
         }
//----
      return(0);
   }
//+------------------------------------------------------------------+

Comments