b_Kaufman_Volatility

Download script
Author: barmenteros
b_Kaufman_Volatility

This tool is designed to measure and visualize market activity by tracking price fluctuations over a specific timeframe. Instead of looking at the direction of the market (whether prices are going up or down), this indicator focuses exclusively on how much "movement" is occurring.

How it Works

The logic operates based on a user-defined period, which determines how many previous price candles the tool should analyze to calculate its current reading.

  1. Measuring Movement: For every point on the chart, the script looks back at the number of candles defined in your settings. It calculates the difference between each consecutive closing price.
  2. Aggregating Intensity: It takes the absolute value of these differences—meaning it treats a jump down just as significant as a jump up—and adds them all together.
  3. Visualizing Volatility: The result is a single value that represents the total "distance" traveled by the price during that timeframe.

What This Means for You

By summarizing these movements into one value, the indicator provides a clear picture of market energy:

  • High Values: When the indicator shows a large reading, it signifies high volatility. This suggests that the market is moving aggressively, with large price swings occurring in a short amount of time.
  • Low Values: A smaller reading indicates a "quieter" market. This suggests that prices are consolidating or moving very slowly with minimal fluctuation.

Customization Options

You can adjust how the information is presented to suit your trading style:

  • Period: You can increase or decrease the number of candles analyzed to capture longer-term volatility trends or focus on immediate, short-term fluctuations.
  • Visual Style: You can choose to view this data as a continuous line, which is helpful for spotting smooth trends in activity, or as a histogram (vertical bars), which makes it easier to identify specific spikes in market movement.
Miscellaneous
It issuies visual alerts to the screenImplements a curve of type %1
5 Views
0 Downloads
0 Favorites
b_Kaufman_Volatility
//+--------------------------------------------------------------------------------------------------+
//|                                                                         b_Kaufman_Volatility.mq4 |
//|                                                                    Copyright © 2011, barmenteros |
//|                                                            http://www.mql4.com/users/barmenteros |
//+--------------------------------------------------------------------------------------------------+
#property copyright "barmenteros"
#property link      "barmenteros.fx@gmail.com"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red

// ---- inputs
// ERperiod    It should be >0. If not it will be autoset to default value
// histogram   [true] - histogram style on; [false] - histogram style off
extern int       ERperiod     =10;              // Efficiency ratio period
extern bool      histogram    =false;           // Histogram switch
extern int       shift        =0;               // Sets offset

// ---- buffers
double KVBfr[];

// ---- global variables
double   noise;

//+--------------------------------------------------------------------------------------------------+
//| Custom indicator initialization function                                                         |
//+--------------------------------------------------------------------------------------------------+
int init()
  {
   string short_name;
   
   // ---- checking inputs
   if(ERperiod<=0)
      {
       ERperiod=10;
       Alert("ERperiod readjusted");
      }                        
   
   // ---- drawing settings
   if(!histogram) SetIndexStyle(0,DRAW_LINE);
   else           SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexLabel(0,"KVolatility");
   SetIndexShift(0,shift);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
   short_name="KVolatility(";
   IndicatorShortName(short_name+ERperiod+")");

   // ---- mapping
   SetIndexBuffer(0,KVBfr);

   // ---- done
   return(0);
  }

//+--------------------------------------------------------------------------------------------------+
//| Custom indicator iteration function                                                              |
//+--------------------------------------------------------------------------------------------------+
int start()
  {
   // ---- optimization
   if(Bars<ERperiod+2) return(0);
   
   int counted_bars=IndicatorCounted(),
       limit, maxbar,
       i;
   
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   
   limit=Bars-counted_bars-1;
   maxbar=Bars-1-ERperiod;
   if(limit>maxbar) limit=maxbar;

   // ---- main cycle
   for(i=limit; i>=0; i--)
      {
       noise=Volatility(i);
       if(noise==EMPTY_VALUE) continue;
       KVBfr[i]=noise;
      }
   
   // ----
   return(0);
  }

double Volatility(int initialbar)
   {
    if(initialbar>Bars-ERperiod-1) return(EMPTY_VALUE);
    int j;
    double v=0.0;
    for(j=0; j<ERperiod; j++)
      v+=MathAbs(Close[initialbar+j]-Close[initialbar+1+j]);
    return(v);
   }

Comments