ATR_Ratio_v1a

Download script
ATR_Ratio_v1a

This script is a custom technical analysis tool designed to help traders visualize the relationship between different levels of market volatility. It works by comparing how much a price moves over short periods versus longer periods, smoothing that data into a readable trend line.

Core Logic Overview

The tool operates through a three-step calculation process:

1. Volatility Measurement (ATR) The script utilizes the Average True Range (ATR), which is a standard industry metric used to measure how much an asset's price fluctuates on average. It identifies two different types of volatility:

  • Fast Volatility: Captures rapid, short-term price swings.
  • Slow Volatility: Captures broader, long-term market movement.

2. The Ratio Calculation Instead of looking at these movements in isolation, the script calculates a Ratio. By dividing the Fast Volatility by the Slow Volatility, the tool determines the relative intensity of current price action.

  • If the ratio is high, it suggests that short-term price swings are significantly larger than the historical average for that timeframe.
  • If the ratio is low, it indicates that the market is currently moving more calmly relative to its broader history.

3. Signal Smoothing Raw volatility ratios can often appear "choppy" or jumpy on a chart, making them difficult to read at a glance. To solve this, the script applies a Moving Average (MA) to the calculated ratio. This smooths out the minor fluctuations and highlights the underlying trend of the volatility relationship.

How it appears on your chart

The result is displayed in a separate window below your main price chart. It provides two distinct lines:

  • The Base Ratio: Shows the direct comparison between fast and slow volatility.
  • The Signal Line: A smoothed version of that ratio, which helps traders identify when a change in market "energy" is becoming a sustained trend rather than just a temporary spike.

By using this tool, you can better understand whether the current market environment is experiencing an abnormal surge in activity or if it is following a steady, established pace.

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

//---- indicator settings

#property  indicator_separate_window

#property  indicator_buffers 2

#property  indicator_color1  Purple

#property  indicator_color2  LightSeaGreen

//---- 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
extern int ShowBars = 500;

//---- 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(1,0.0000);
  SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
  SetIndexBuffer(1,preatrbuffer);
  SetIndexLabel(1,"FastATR/SlowATR");
  SetIndexDrawBegin(1,draw_begin0);
  
  SetIndexEmptyValue(0,0.0000);
  SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
  SetIndexBuffer(0,finalatrbuffer);
  SetIndexLabel(0," ("+SignalLine_Period+") Period Ma of ATRRatio");
  SetIndexDrawBegin(0,draw_begin0);
  
  
//---- name for DataWindow and indicator subwindow label
  
  IndicatorShortName("ATR_Ratio_v1a");
  
  
//---- 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;
  limit = ShowBars;
  if (ShowBars >= Bars) limit = Bars - 1;

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

//---- 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,0,SignalLine_Period,SignalLineShift,SignalLineMa_Method,i); }

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

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

Comments