Author: Yuriy Tokman (YTG)

This script is designed to function as a specialized visual indicator for the MetaTrader trading platform. Its primary purpose is to calculate and display the "speed" or rate of change within Bolinger Bands, allowing traders to observe how quickly price momentum is moving relative to standard volatility boundaries.

Core Logic Overview

The script focuses on measuring velocity by comparing the current state of Bollinger Bands against their previous values. Instead of just showing the bands themselves, it transforms that data into a numerical representation of "speed."

Key Components of the Logic:

1. Input Parameters The tool is highly customizable through several user-defined settings:

  • Period: Determines the lookback time used to calculate the average price and volatility.
  • Deviation: Controls how wide or narrow the bands are (standard volatility).
  • Bands Shift: Allows the user to offset the visual placement of the data on the chart.
  • Applied Price: Lets the user choose which price type (such as Close, Open, High, or Low) the calculation should be based on.

2. Speed Calculation Mechanism The heart of the script lies in its calculation of two distinct buffers (visual lines):

  • It identifies the values of the Upper and Lower Bollinger Bands for the current moment.
  • It then subtracts the value of those same bands from the previous candle/bar.
  • By dividing this difference by the point value of the currency, it generates a "speed" figure.

3. Visual Representation The script outputs two separate lines on a dedicated indicator window:

  • Buffer 1: Represents the speed of one boundary of the band.
  • Buffer 2: Represents the speed of the opposite boundary.

How it Benefits the User

Rather than looking at a static price, this logic helps a trader see how "fast" the market is accelerating or decelerating. When the lines on the indicator move sharply, it indicates significant momentum. When they flatten out, it suggests that the market's movement is stabilizing or losing steam.

By providing these values in a separate window, the script allows for a cleaner chart environment while giving the trader a dedicated view of underlying price velocity.

Indicators Used
Bollinger bands indicator
Miscellaneous
Implements a curve of type %1
16 Views
1 Downloads
0 Favorites
speed BB
ÿþ//+------------------------------------------------------------------+

//|                                                           bb.mq4 |

//|                                               Yuriy Tokman (YTG) |

//|                       https://www.mql5.com/ru/users/satop/seller |

//+------------------------------------------------------------------+

#property copyright "Yuriy Tokman (YTG)"

#property link      "https://www.mql5.com/ru/users/satop/seller"

#property version   "1.00"

#property strict

#property indicator_separate_window



#property indicator_buffers 2

#property indicator_width1 2

#property indicator_width2 2

#property indicator_color1 clrGreen

#property indicator_color2 clrRed



input int    period = 250;                // ?5@8>4 

input double deviation = 2;               // :>;-2> AB0=40@B=KE >B:;>=5=89 

input int    bands_shift = 0;             // A4283 >B=>A8B5;L=> F5=K 

input int    applied_price = PRICE_CLOSE; // B8? F5=K 



//---- buffers period,deviation,bands_shift,applied_price

double BU1[];

double BU2[];



string i_name ="";

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

 i_name = "speed BB("+DoubleToStr(1,0)+")";

 IndicatorShortName(i_name);

 IndicatorDigits(1);



   SetIndexStyle(0,DRAW_LINE);

   SetIndexBuffer(0,BU1);

   SetIndexLabel(0,i_name);

   SetIndexDrawBegin(0,period);

   

   SetIndexStyle(1,DRAW_LINE);

   SetIndexBuffer(1,BU2);

   SetIndexLabel(1,i_name);

   SetIndexDrawBegin(1,period);    

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//---

   int limit=rates_total-prev_calculated;

   if(prev_calculated==0)limit--;

   else  limit++;

   

   if(limit<period)return(0);

   if(limit>=rates_total-1)limit = rates_total - period;

     

   for( int i=limit; i>=0 && !IsStopped(); i--)

    {

      BU1[i]=(iBB(1,i) - iBB(1,i+1))/Point;

      BU2[i]=(iBB(2,i) - iBB(2,i+1))/Point;        

    }   

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

 double iBB(int buf =0, int shi = 0)

  {

   return iBands(Symbol(),0,period,deviation,bands_shift,applied_price,buf,shi);

  }

Comments