Virus Indicator

Download script
Author: Copyright � 2005, MetaQuotes Software Corp.
Virus Indicator

This tool is designed to provide a visual representation of market volatility by calculating the "Average True Range" over a specific timeframe. Rather than focusing on the direction of price (whether it is going up or down), this script focuses on the magnitude of price movement, helping traders understand how much a currency pair or asset typically fluctuates within a given period.

Core Logic and Functionality

The script operates based on three primary logical steps:

1. Defining the Observation Window The tool uses a user-defined parameter (the "Ranging Period") to determine how far back in time it should look to gather data. By default, it looks at the last 14 candles. This allows the user to toggle between a shorter timeframe for fast-moving reactions or a longer timeframe for broader market context.

2. Identifying Price Extremes For every point on the chart, the script scans the specified number of previous candles to identify two critical data points:

  • The highest price reached during that period.
  • The lowest price reached during that period.

By identifying these extremes, the tool can measure the total "swing" or "range" of the market. It essentially calculates the distance between the ceiling and the floor of price action within that window.

3. Calculating the Range Value Once the highest and lowest points are identified, the script calculates the difference between them. This numerical value represents the volatility of the current period.

  • The tool then plots these values on a separate window below your main trading chart.
  • The resulting line visually fluctuates based on market activity: when the line moves higher, it indicates that the market is experiencing wider price swings (high volatility). When the line moves lower, it indicates that the market is becoming more compressed or "quiet" (low volatility).

Summary for the User

In plain terms, this script acts as a "volatility thermometer." It ignores the noise of individual price ticks and instead draws a smooth line that tells you how wide the market's heartbeat is. It is primarily used to gauge whether the market is moving aggressively or staying within a tight, stable range, allowing for a clearer understanding of expected price movement intensity.

Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
Virus Indicator
//+------------------------------------------------------------------+
//|                                                          ATR.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 1
#property indicator_color1 DodgerBlue
//---- input parameters
extern int RangingPeriod=14;
//---- buffers
double AtrBuffer[];
double TempBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- 1 additional buffer used for counting.
   IndicatorBuffers(2);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,AtrBuffer);
   SetIndexBuffer(1,TempBuffer);
//---- name for DataWindow and indicator subwindow label
   short_name="Virus("+RangingPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----
   SetIndexDrawBegin(0,RangingPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Average True Range                                               |
//+------------------------------------------------------------------+
int start()
  {
   int i,counted_bars=IndicatorCounted();
//----
   if(Bars<=RangingPeriod) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=RangingPeriod;i++) AtrBuffer[Bars-i]=0.0;
//----
   i=Bars-counted_bars-1;
   while(i>=0)
     {
      double high=High[iHighest(NULL, 0, 2, RangingPeriod, i)];
      double low =Low[iLowest(NULL, 0, 2, RangingPeriod, i)];
      if(i==Bars-1) TempBuffer[i]=high-low;
      else
        {
         double prevclose=Close[i+1];
         TempBuffer[i]=high - low;
        }
      i--;
     }
//----
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   for(i=0; i<limit; i++)
      AtrBuffer[i]=TempBuffer[i];
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments