atr_value_indicator

Download script
Author: Copyright 2016, Hossein Nouri.
atr_value_indicator

This tool is designed to provide traders with a real-time visual representation of market volatility directly on their trading charts. By calculating and displaying specific data points, it helps users understand the "normal" range of price movement for a given asset at any specific moment.

Core Functionality

The script focuses on the Average True Range (ATR), a standard financial metric that measures how much an asset typically moves over a set period. Instead of requiring you to manually calculate these figures, the tool automates the process and projects the result onto your screen as a clear, readable label.

How the Logic Works

The script operates through three main logical phases:

1. Data Collection and Calculation The tool looks at a specific window of recent price history (defined by a user-adjustable period). It analyzes the high, low, and closing prices to determine the average price movement. This raw data is then processed using a "Multiplier." For example, if the market typically moves 10 points but you want to see what a 200% move looks like, the tool scales the calculation accordingly.

2. Unit Conversion To ensure the information is useful for different types of traders, the script includes logic to convert these raw numbers into human-readable formats. It can switch between "Points" and "Pips," depending on your preference, ensuring that the value displayed aligns with how you typically measure price changes.

3. Dynamic Visual Display Rather than cluttering the chart with complex lines or graphs, the script creates a dedicated text label in the upper right-hand corner of your screen. This label is "dynamic," meaning it updates automatically every time the market moves (on every "tick").

User Experience Features

  • Real-Time Updates: The text on your screen refreshes constantly, providing an up-to-the-second view of current volatility.
  • Customizable Visuals: You can control how the information looks, including the font size and the color of the text, to ensure it remains visible against your specific chart background.
  • Contextual Information: The display doesn't just show a number; it provides context by showing the percentage of the ATR being viewed and the period used for the calculation, making it easier to interpret quickly during live trading.
Indicators Used
Indicator of the average true range
7 Views
0 Downloads
0 Favorites
atr_value_indicator
//+------------------------------------------------------------------+
//|                                           ATR Value Indicator.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Hossein Nouri."
#property link      "https://www.mql5.com/en/users/hsnnouri"
#property version   "1.00"
#property description "Displaying ATR(Average True Range) value in pips or points." 
#property strict
#property indicator_chart_window
//--- input parameters
enum valueType
{
   Points=0,
   Pips=1,
};
input int      ATRPeriod=14;
input double   Multiplier=2.0;
input valueType display=0;
input color    labelColor=clrRed;
input int      fontSize=10;
#define OBJ_NAME "ATRIndicatorObj"
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   ShowATR();
//---
   return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
{
   ObjectDelete(OBJ_NAME);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   ShowATR();
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
void ShowATR()
{
   static double ATR;
   
   ATR = iATR(Symbol(),0,ATRPeriod,0);
   ATR = (ATR * Multiplier) * MathPow(10,Digits - display);
   DrawATROnChart(ATR);
}
void DrawATROnChart(double ATR)
{
   string Dis;
   if(display==0) Dis=" Points";
   if(display==1) Dis=" Pips";
   string s = (string)(Multiplier * 100) + "% of ATR ("+(string)ATRPeriod+"):"+DoubleToStr(ATR,0)+ Dis;
   
   if(ObjectFind(OBJ_NAME) < 0)
   {
      ObjectCreate(OBJ_NAME, OBJ_LABEL, 0, 0, 0);
      ObjectSet(OBJ_NAME, OBJPROP_CORNER, CORNER_RIGHT_UPPER);
      ObjectSet(OBJ_NAME, OBJPROP_YDISTANCE, 30);
      ObjectSet(OBJ_NAME, OBJPROP_XDISTANCE, 0);
      ObjectSet(OBJ_NAME,OBJPROP_SELECTABLE,false);
      ObjectSetText(OBJ_NAME, s, fontSize, "Arial", labelColor);
   }
   
   ObjectSetText(OBJ_NAME, s);
   
   WindowRedraw();
}

Comments