ATR ratio_v1

Download script
Author: Copyright � 2005, Luis Guilherme Damiani
ATR ratio_v1

This script is designed as a visual analysis tool for MetaTrader that helps traders measure and compare market volatility over different timeframes. Instead of looking at price directly, it focuses on the "Average True Range" (ATR)—a standard metric used to determine how much an asset typically moves in a given period.

How the Logic Works

The core objective of this tool is to create a ratio between short-term market fluctuations and long-term market trends. It accomplishes this through three primary components:

1. Volatility Measurement The script looks at two different windows of time simultaneously:

  • Short-term Volatility: It calculates the average price movement over a small, recent period (defined by the "short_atr" setting).
  • Long-term Volatility: It calculates the average price movement over a much larger, historical period (defined by the "long_atr" setting).

2. The Ratio Calculation The script then performs a mathematical division: it takes the short-term volatility and divides it by the long-term volatility. By doing this, it creates a relative percentage of activity. This allows you to see if the market is currently experiencing an unusual "spike" in movement compared to its historical norm, or if it is settling into a period of relative calm.

3. Visual Representation The indicator displays this information in a separate window on your chart using two distinct lines:

  • The Baseline: A horizontal reference line (the "triglevel") acts as the equilibrium point. When the ratio is at 1.00, it means current volatility perfectly matches historical averages.
  • The Ratio Line: A secondary line moves up and down based on the calculation described above.

Practical Application

For a user, this provides a quick visual cue of market "heat." When the ratio line rises significantly above the baseline, it suggests that current price action is becoming more volatile than usual. Conversely, when it drops below, it indicates that the market is moving more slowly or with less intensity than what has been seen over the longer term.

Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
ATR ratio_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                    ATR ratio.mq4 |
//|                         Copyright © 2005, Luis Guilherme Damiani |
//|                                      http://www.damianifx.com.br |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Luis Guilherme Damiani"
#property link      "http://www.damianifx.com.br"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Silver
#property indicator_color2 Violet
//---- input parameters
extern int       short_atr=7;
extern int       long_atr=49;
extern double    triglevel=1.00;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   //Comment("ATR ratio= "+short_atr+" / "+long_atr);
   for(int i=0;i<Bars-counted_bars;i++)
   {
      ExtMapBuffer1[i]=triglevel;
      double sa=iATR(NULL,0,short_atr,i);
      ExtMapBuffer2[i]= sa/iATR(NULL,0,long_atr,i);   
   }
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments