ATR_Ratio_v1

Download script
ATR_Ratio_v1

This script is a custom technical analysis tool designed to measure and smooth the relationship between different levels of market volatility. Instead of looking at price alone, it focuses on how the intensity of price movements changes over time.

Core Concept: The ATR Ratio

The primary logic of this tool revolves around the Average True Range (ATR). In trading, the ATR is a standard measure of how much an asset typically moves in a given period. This script takes two different ATR measurements—a "Fast" one and a "Slow" one—and compares them against each other to create a ratio.

  • The Fast Measurement: Tracks short-term price fluctuations.
  • The Slow Measurement: Tracks longer-term price fluctuations.

By dividing the Fast measurement by the Slow measurement, the tool creates a unique value that identifies whether current market volatility is expanding or contracting relative to its historical average. For example, if the ratio is high, it suggests that recent price swings are significantly larger than usual; if the ratio is low, it indicates a period of relative calma or consolidation.

Smoothing and Trend Identification

Because raw volatility data can often be "noisy" (jittery and inconsistent), the script applies a secondary layer of logic to make the data easier to read. It takes the calculated ratio and runs it through a Moving Average.

This smoothing process helps filter out minor price spikes, allowing you to see the broader trend of market volatility more clearly. The user can customize how this smoothing behaves by choosing different mathematical methods (such as Simple, Exponential, or Weighted averages) and adjusting the periods to prioritize either recent data or older history.

Visual Representation

The tool appears in its own dedicated window below the price chart, displaying two distinct lines:

  1. The Fast ATR Line: Represents the raw volatility ratio.
  2. The Signal Line: Represents the smoothed average of that ratio.

By observing these two lines together, a user can identify shifts in market dynamics—essentially seeing when the "mood" of the market is shifting from stable to volatile (or vice versa) before those changes become obvious on the price chart alone.

Indicators Used
Indicator of the average true rangeMoving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
ATR_Ratio_v1
//+------------------------------------------------------------------+
//|                                               Hull_Style_ATR.mq4 |
//+------------------------------------------------------------------+

//---- indicator settings

#property  indicator_separate_window

#property  indicator_buffers 2

#property  indicator_color1  LightSeaGreen

#property  indicator_color2  Purple

//---- indicator parameters

extern int FastATR_Period      = 14;
extern int SlowATR_Period      = 28;
extern int SignalLine_Period   = 9;
extern int SignalLineShift     =  3;
extern int SignalLineMa_Method =  0; // 0 SMA , 1 EMA , 2 SMMA , 3 LWMA

//---- indicator buffers

double preatrbuffer[];
double finalatrbuffer[];

int    draw_begin0;

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

int init()
 {

//---- indicator buffers mapping
  
//---- drawing settings
  
  draw_begin0 = SlowATR_Period;
  
  SetIndexEmptyValue(0,0.0000);
  SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
  SetIndexBuffer(0,preatrbuffer);
  SetIndexLabel(0,"FastATR");
  SetIndexDrawBegin(0,draw_begin0);
  
  SetIndexEmptyValue(1,0.0000);
  SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
  SetIndexBuffer(1,finalatrbuffer);
  SetIndexLabel(1," ("+SignalLine_Period+") Period Ma of ATRRatio");
  SetIndexDrawBegin(1,draw_begin0);
  
  
//---- name for DataWindow and indicator subwindow label
  
  IndicatorShortName("ATR_Ratio");
  
  
//---- 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++) { finalatrbuffer[Bars-i]=0; preatrbuffer[Bars-i]=0; }
   }

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

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

//---- preadxbuffer
  
  for(i=0; i<limit; i++)
    { preatrbuffer[i] = (iATR(Symbol(), 0, FastATR_Period, i)/Point) / (iATR(Symbol(), 0, SlowATR_Period, i)/Point); }

//---- finaladxbuffer
  
  for(i=0; i<limit; i++)
    { finalatrbuffer[i]=iMAOnArray(preatrbuffer,Bars,SignalLine_Period,SignalLineShift,SignalLineMa_Method,i); }

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

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

Comments