ATR_Ratio_v2

ATR_Ratio_v2

This tool is designed to help traders visualize and analyze market volatility by comparing different speeds of price movement. Instead of looking at raw price action, this indicator focuses on "volatility ratios"—specifically measuring how much the market is moving relative to its own historical patterns.

Core Logic Overview

The script functions by calculating two distinct types of volatility measurements simultaneously and then comparing them against one another. By creating a ratio between these two values, it helps identify when current market activity is unusually high or low compared to recent trends.

Key Components of the Analysis

1. The Dual-Speed Volatility Comparison (ATR Ratio) The indicator uses a common volatility metric called Average True Range (ATR). It calculates this across two different time horizons:

  • Fast Perspective: A short-term window that captures immediate, "heartbeat" fluctuations in the market.
  • Slow Perspective: A longer-term window that establishes the broader historical "norm" for price movement.

The script then divides the Fast value by the Slow value. This creates a single line on your chart:

  • When this ratio is high, it suggests that current volatility is spiking significantly compared to the recent past.
  • When this ratio is low, it indicates that the market is becoming quieter or more consolidated than usual.

2. The Deviation Analysis (ATR Deviation Ratio) To provide a deeper layer of insight, the script performs a secondary calculation based on "Standard Deviation." Rather than just looking at the raw volatility numbers, it looks at how much those volatility numbers are varying.

Specifically, it tracks:

  • The fluctuation of the short-term volatility.
  • The fluctuation of the long-term volatility.

By creating a ratio between these two deviations, the indicator provides a "stability" metric. This helps a trader understand if the current change in market behavior is a steady, consistent shift or a chaotic, erratic spike.

How to Read the Results

The tool outputs two distinct lines in a separate window:

  • Primary Line (LightSeaGreen): Represents the basic relationship between short-term and long-term volatility. It tells you how much the market is moving right now relative to the past.
  • Secondary Line (Purple): Represents the relationship between the changes in those volatilities. It helps identify the nature of that movement (whether it is accelerating or stabilizing).

By observing where these lines sit relative to the "1" level, traders can better sense whether the market is entering a period of high-intensity activity or retreating into a calm, low-volatility phase.

Indicators Used
Indicator of the average true rangeStandard Deviation indicator
Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
ATR_Ratio_v2
//+------------------------------------------------------------------+
//|                                                 ATR_Ratio_v2.mq4 |
//+------------------------------------------------------------------+

//---- indicator settings

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 LightSeaGreen
#property indicator_color2 Purple

#property indicator_level1 1
#property indicator_minimum 0.5
#property indicator_maximum 1.5

//---- indicator parameters

extern int FastATR_Period      = 5;
extern int SlowATR_Period      = 14;
extern int ShowBars            = 500;

//---- indicator buffers

double ATRFast[],ATRSlow[];
double ATR_Ratio_Buffer[];
double ATRFastDev[],ATRSlowDev[];
double ATRDev_Ratio_Buffer[];

int    draw_begin0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
 {

//---- additional buffer used for counting.
   IndicatorBuffers(6);
  
//---- drawing settings
  
  draw_begin0 = SlowATR_Period;
  
  SetIndexEmptyValue(0,0.0000);
  SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
  SetIndexBuffer(0,ATR_Ratio_Buffer);
  SetIndexLabel(0,"ATRFast/ATRSlow");
  SetIndexDrawBegin(0,draw_begin0);
  
  SetIndexEmptyValue(1,0.0000);
  SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
  SetIndexBuffer(1,ATRDev_Ratio_Buffer);
  SetIndexLabel(1,"ATRFastDev/ATRSlowDev");
  SetIndexDrawBegin(1,draw_begin0);
  
  SetIndexStyle(2,DRAW_NONE);
  SetIndexBuffer(2,ATRFast);

  SetIndexStyle(3,DRAW_NONE);
  SetIndexBuffer(3,ATRSlow);

  SetIndexStyle(4,DRAW_NONE);
  SetIndexBuffer(4,ATRFastDev);

  SetIndexStyle(5,DRAW_NONE);
  SetIndexBuffer(5,ATRSlowDev);
  
//---- name for DataWindow and indicator subwindow label
  
  IndicatorShortName("ATR_Ratio_v2");
  
  
//---- initialization done
  return(0);
 }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int start() {

   int limit,i,shift;
   int counted_bars=IndicatorCounted();

//---- check for possible errors
  if(counted_bars<1)
      for(i=1;i<=draw_begin0;i++) 
         ATRDev_Ratio_Buffer[Bars-i]=0; ATR_Ratio_Buffer[Bars-i]=0;

//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
//limit=Bars-counted_bars;
   limit = ShowBars;
   if (ShowBars >= Bars) limit = Bars - 1;

//-----------------------------------------------------------------------------------------------------------------

//---- preadxbuffer
  
   for(i=0; i<limit; i++) {
      ATRFast[i]=iATR(Symbol(),0,FastATR_Period,i);
      ATRSlow[i]=iATR(Symbol(),0,SlowATR_Period,i);
      if ( ATRSlow[i]!=0 ) 
         ATR_Ratio_Buffer[i] = ATRFast[i]/ATRSlow[i];
   }

//---- finaladxbuffer
  
   for(i=0; i<limit; i++) {
      ATRFastDev[i]= iStdDevOnArray(ATRFast,0,5,0,MODE_LWMA,i);
      ATRSlowDev[i]= iStdDevOnArray(ATRSlow,0,5,0,MODE_LWMA,i);
      if ( ATRSlowDev[i]!=0 ) 
         ATRDev_Ratio_Buffer[i]=ATRFastDev[i]/ATRSlowDev[i];
   }

//-----------------------------------------------------------------------------------------------------------------

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

Comments