Volatility4

Download script
Author: Copyright � 2007, MetaQuotes Software Corp.
Volatility4

This tool is designed to help traders visualize and measure the "intensity" of price movements within a specific timeframe. Rather than looking at the price itself, this indicator focuses on the range—the distance between the highest and lowest points—to determine how much the market is fluctuating.

How It Works

The logic behind this script can be broken down into three main components:

1. Measuring the Price Range The core of the calculation identifies two key averages: one based on the "High" prices and one based on the "Low" prices over a set period (which you can customize). By subtracting the Low average from the High average, the tool calculates the vertical distance of the market's movement. This essentially tells you how much "room" the price is covering during that specific window of time.

2. Scaling the Data To make these measurements easier to read on a standard chart, the script multiplies the resulting difference by a factor of 10,000. This converts the raw price movements into a more readable numerical format, allowing for a clearer visual representation of volatility trends.

3. Visual Reference Points The indicator provides several clear horizontal guide lines (at intervals of 100 units). These act as "benchmarks." By watching the plotted line move against these levels, you can quickly identify:

  • Calm Markets: When the line stays low and flat, indicating very little price movement.
  • High Activity: When the line spikes upward, signaling that the market is becoming more active or turbulent.

Summary for Traders

In short, this script acts as a "heartbeat monitor" for the market. It filters out the noise of individual price ticks and provides a smoothed line that shows you whether the market is currently expanding or contracting. It allows you to see at a glance if the current environment is stable enough for your strategy or if the market is experiencing significant swings.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
Volatility4
//+------------------------------------------------------------------+
//|                                                   Volatility.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 1
//---- input parameters
extern int VolatilityPeriod=5;
//---- indicator buffers
double MainBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetLevelValue(0,50);
   SetLevelStyle(0,1,Black);
   SetLevelValue(1,100);
   SetLevelStyle(0,0,Black);
   SetLevelValue(2,200);
   SetLevelStyle(0,0,Black);
   SetLevelValue(3,300);
   SetLevelStyle(0,0,Black);
   SetLevelValue(4,400);
   SetLevelStyle(0,0,Black);
   SetIndexStyle(0,DRAW_LINE,0,2,SteelBlue);
   SetIndexBuffer(0, MainBuffer);
   SetIndexDrawBegin(0,VolatilityPeriod);
   IndicatorDigits(Digits+2);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Volatility("+VolatilityPeriod+")");
   SetIndexLabel(0,"Volatility");
//---- initialization done
   return(0);
  }

//+------------------------------------------------------------------+
//|Volatility                                                        |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- Volatility counted
   for(int i=0; i<limit; i++)
      MainBuffer[i]=(iMA(NULL,0,VolatilityPeriod,0,MODE_SMA,PRICE_HIGH,i)-iMA(NULL,0,VolatilityPeriod,0,MODE_SMA,PRICE_LOW,i))*10000;
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments