This script is designed as a visual information tool for traders using the MetaTrader platform. Its primary purpose is to provide a clear, real-time display of price movement statistics directly on your trading chart.
Core Functionality
The tool automatically calculates and displays two specific types of price ranges based on the most recently completed candle (the previous bar). Instead of forcing you to manually calculate price differences, it projects these numbers as text labels in a designated corner of your screen.
Key Data Points Displayed
- OC Range (Open-Close): This identifies the "body" of the previous candle. It measures the distance between where the price opened and where it closed. This helps you quickly gauge the strength or sentiment of the last completed move.
- HL Range (High-Low): This identifies the total volatility of the previous candle. It measures the entire distance from the highest point reached to the lowest point reached. This allows you to see how much "ground" was covered, regardless of where the price ended up.
Visual Customization
The script is built to be user-friendly and visually adjustable to fit your specific trading layout. You can customize several visual aspects:
- Positioning: You can choose which corner of the chart the information appears in (e.g., Top Left, Bottom Right, etc.).
- Formatting: You can adjust the font size, choose whether the text is bold, and select the color to ensure it stands out against your background.
- Spacing: The script allows you to set specific horizontal and vertical offsets, so the labels won't overlap with other indicators or price action.
Technical Behavior
Every time the market updates, the script refreshes these calculations. It automatically handles different pricing formats (ensuring the numbers are scaled correctly regardless of whether you are trading forex, stocks, or commodities) and ensures that only the most recent data is displayed by clearing out old labels before drawing new ones.
//+------------------------------------------------------------------+
//| 0 - OHLC Range.mq4 |
//| Copyright 2014, MetaQuotes Software Corp. |
//| http://www.mql5.com
//
//| File45 - https://login.mql5.com/en/users/file45/publications
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
input color Font_Color = DodgerBlue;
input int Font_Size = 11;
input bool Font_Bold = true;
input int Left_Right = 20;
input int Up_Down = 170;
input ENUM_BASE_CORNER Corner = 1;
string Text_OC = "OC";
string Text_HL = "HL";
string The_Font;
double Pointz;
ENUM_ANCHOR_POINT corner_point;
int OnInit()
{
Pointz = Point;
// 1, 3 & 5 digits pricing
if (Point == 0.1) Pointz =1;
if ((Point == 0.00001) || (Point == 0.001)) Pointz *= 10;
switch(Corner)
{
case 0: corner_point = ANCHOR_LEFT_UPPER; break;
case 1: corner_point = ANCHOR_LEFT_LOWER; break;
case 2: corner_point = ANCHOR_RIGHT_LOWER; break;
case 3: corner_point = ANCHOR_RIGHT_UPPER;
}
if(Font_Bold == true)
{
The_Font = "Arial Bold";
}
else
{
The_Font = "Arial";
}
return(INIT_SUCCEEDED);
}
int deinit()
{
ObjectDelete("OC_Rang");
ObjectDelete("HL_Rang");
return(0);
}
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[])
{
string Open_CLose, Open_Close_Range;
Open_CLose = "OC_Rang";
// Open_Close_Range = DoubleToStr(MathAbs((Open[1] - Close[1]) / Pointz), 2);
Open_Close_Range = DoubleToStr(MathAbs((Open[1] - Close[1])/Point),0);
if (ObjectFind(Open_CLose) != -1) ObjectDelete(Open_CLose);
ObjectCreate(Open_CLose,OBJ_LABEL,0,0,0);
ObjectSetText(Open_CLose, Text_OC + " " + Open_Close_Range, Font_Size, The_Font, Font_Color);
ObjectCreate(Open_CLose, OBJ_LABEL, 0,0,0 );
ObjectSetInteger(0,"Ask",OBJPROP_ANCHOR,corner_point);
ObjectSet(Open_CLose, OBJPROP_CORNER, Corner);
ObjectSet(Open_CLose, OBJPROP_XDISTANCE, Left_Right);
ObjectSet(Open_CLose, OBJPROP_YDISTANCE, Up_Down );
string High_Low, High_Low_Range;
High_Low = "HL_Rang";
// High_Low_Range = DoubleToStr(MathAbs((High[1] - Low[1]) / Pointz), 2);
High_Low_Range = DoubleToStr(MathAbs((High[1] - Low[1])/Point),0);
if (ObjectFind(High_Low) != -1) ObjectDelete(High_Low);
ObjectCreate(High_Low,OBJ_LABEL,0,0,0);
ObjectSetText(High_Low, Text_HL + " " + High_Low_Range, Font_Size, The_Font, Font_Color);
ObjectCreate(High_Low, OBJ_LABEL, 0,0,0 );
ObjectSetInteger(0,"Ask",OBJPROP_ANCHOR,corner_point);
ObjectSet(High_Low, OBJPROP_CORNER, Corner);
ObjectSet(High_Low, OBJPROP_XDISTANCE, Left_Right);
ObjectSet(High_Low, OBJPROP_YDISTANCE, Up_Down + 1.5*Font_Size);//}
return(rates_total);
}
Comments