0_-_Constant_Range_Detector_-_v2

Download script
Author: Copyright � 2013, File45
0_-_Constant_Range_Detector_-_v2

This script is designed as an on-screen visual aid for traders using the MetaTrader platform. Its primary purpose is to provide a real-time calculation of price volatility based on the previous completed candle, displaying this information directly on your trading chart in a clean, customizable format.

Core Functionality

The logic operates by calculating the "Range" of the most recently closed price bar. It identifies the highest price reached and the lowest price dropped during that period, determines the total distance between those two points, and converts that distance into a standard numerical value (points).

Key Logic Steps:

  • Price Normalization: The script automatically detects the precision of your specific currency pair (for example, whether it uses 4 or 5 decimal places). This ensures that the calculated range is always displayed in a consistent, readable format regardless of which market you are trading.
  • Real-Time Calculation: Every time the chart refreshes, the script looks back at the previous candle to find the absolute difference between its high and low points.
  • Dynamic Display: Instead of just performing a background calculation, the script creates a visual label on your screen. It combines a custom text prefix (which you can define) with the calculated numerical range.
  • Visual Customization: The logic allows for easy adjustments to how this information appears on your workspace. You can modify the font size, color, and thickness (boldness), as well as specify exactly where on the screen the data should appear (using corner coordinates and distance offsets).

User Experience

For the trader, this means you don't have to manually calculate the volatility of previous price action. The script provides a constant, "glanceable" metric that helps you quickly assess how much price movement occurred in the last period, helping to inform your strategy on current market sentiment.

6 Views
0 Downloads
0 Favorites
0_-_Constant_Range_Detector_-_v2
#property copyright "Copyright © 2013, File45"
#property link      "http://codebase.mql4.com/en/author/file45"
 
#property indicator_chart_window
//+------------------------------------------------------------------+
//| START OF DEFAULT OPTIONS                      
//+------------------------------------------------------------------+
extern string Text = "CR";
extern color Font_Color = DodgerBlue;
extern int Font_Size = 11;
extern bool Font_Bold = true;
extern int Left_Right = 25;
extern int Up_Down = 150;
extern int Corner = 1;
//+------------------------------------------------------------------+
//| END OF DEFAULT OPTIONS                      
//+------------------------------------------------------------------+
string The_Font;
double Pointz;
//+------------------------------------------------------------------+
//| Init                       
//+------------------------------------------------------------------+
int init()
{
   Pointz = Point;
    // 1, 3 & 5 digits pricing
   if (Point == 0.1) Pointz =1;
   if ((Point == 0.00001) || (Point == 0.001)) Pointz *= 10;
   
   if(Font_Bold == true)
   {
      The_Font = "Arial Bold";
   }
   else
   {
      The_Font = "Arial";
   }      
  
   return(0);
}
//+------------------------------------------------------------------+
//| Deinit                   
//+------------------------------------------------------------------+
int deinit()
{
   ObjectDelete("CR");
     
   return(0);
}
//+------------------------------------------------------------------+
//| Start                            
//+------------------------------------------------------------------+
int start()
{  
   string name_cr, Constant_Range;
   name_cr = "CR";
   Constant_Range = DoubleToStr(MathAbs((High[1] - Low[1]) / Pointz), 2);
      
   if (ObjectFind(name_cr) != -1) ObjectDelete(name_cr);
   ObjectCreate(name_cr,OBJ_LABEL,0,0,0);
   ObjectSetText(name_cr, Text + " " + Constant_Range, Font_Size, The_Font, Font_Color);
   ObjectCreate(name_cr, OBJ_LABEL, 0,0,0 );
   ObjectSet(name_cr, OBJPROP_CORNER, 1);
   ObjectSet(name_cr, OBJPROP_XDISTANCE, Left_Right);
   ObjectSet(name_cr, OBJPROP_YDISTANCE, Up_Down );//}
      
  return(0);
}

Comments