Constant Range Detector-rev1
Download scriptThis tool is designed as a visual on-screen display for the MetaTrader platform that helps traders monitor specific price movement data at a glance. Instead of cluttering your charts with complex indicators, it provides a clean, real-time text readout based on historical price action.
How the Logic Works
1. Historical Data Analysis The script focuses on a specific "look-back" period. It specifically looks at the price candles that occurred a set number of steps behind the current live price (defined as 8 candles back by default). By analyzing this specific point in time, the tool provides a consistent reference point rather than reacting to the immediate, often volatile, price fluctuations of the current second.
2. Measuring Price Range The core logic calculates the "Range" of those historical candles. It identifies the highest price reached (the peak) and the lowest price reached (the valley) during that specific timeframe. The script then calculates the distance between these two points to determine the total volatility or spread of that candle.
3. Dynamic Scaling To ensure the information is readable regardless of which asset you are trading—whether it is a high-value currency pair, a low-value cryptocurrency, or an index—the script automatically adjusts its internal math. It detects the decimal precision of the market and converts the price range into a standardized numerical value. This ensures that the number displayed on your screen is always easy to interpret.
4. Visual Display Once the calculation is complete, the tool creates a customizable text label on your chart. It combines a prefix (which you can name yourself) with the calculated range value. You have full control over how this information appears, including:
- Positioning: You can move the text to any corner of your screen.
- Styling: You can choose the specific font size, face, and color to match your trading layout.
Summary for the User
Essentially, this script acts as a "Reference Tracker." It looks back at the 8th previous candle, measures how far it moved from top to bottom, and displays that distance as a simple number on your screen. It is a streamlined way to keep track of historical price volatility without having to manually calculate the differences between highs and lows.
#property copyright "Copyright © 2012, File45"
#property link "http://codebase.mql4.com/en/author/file45"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| START OF DEFAULT OPTIONS
//+------------------------------------------------------------------+
extern string Text = "CR";
extern int Corner = 1;
extern int X_Distance = 25;
extern int Y_Distance = 100;
extern color Font_Color = Plum;
extern int Font_Size = 11;
extern string Font_Face = "Verdana Bold";
//+------------------------------------------------------------------+
//| END OF DEFAULT OPTIONS
//+------------------------------------------------------------------+
int Hist_Candle_Number = 8;
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;
return(0);
}
//+------------------------------------------------------------------+
//| Deinit
//+------------------------------------------------------------------+
int deinit()
{
ObjectDelete("CRD");
return(0);
}
//+------------------------------------------------------------------+
//| Start
//+------------------------------------------------------------------+
int start()
{
string name, Constant_Range;
int i;
name = "CRD";
Constant_Range = DoubleToStr(MathRound((High[i+Hist_Candle_Number] - Low[i+Hist_Candle_Number]) / Pointz), 0);
if (ObjectFind(name) != -1) ObjectDelete(name);
ObjectCreate(name,OBJ_LABEL,0,0,0);
ObjectSetText(name, Text + " " + Constant_Range, Font_Size, Font_Face, Font_Color);
ObjectCreate(name, OBJ_LABEL, 0,0,0 );
ObjectSet(name, OBJPROP_CORNER, 1);
ObjectSet(name, OBJPROP_XDISTANCE, X_Distance);
ObjectSet(name, OBJPROP_YDISTANCE, Y_Distance );//}
return(0);
}
//+------------------------------------------------------------------+
Comments