BarRange2
Download scriptThis tool is designed to provide traders with a clear, visual representation of price volatility by calculating and displaying the "Daily Range" directly on the trading chart. Instead of forcing you to manually calculate the distance between the highest and lowest prices reached during a specific period, this script automates that math for every candle on your screen.
How the Logic Works
1. Data Capture and Calculation The script scans the historical data of your chosen currency pair or asset. For every individual candle (bar) on the chart, it identifies two key price points: the highest point reached (High) and the lowest point reached (Low). By subtracting the low from the high, the script determines the total "spread" or range of movement for that specific timeframe.
2. Dynamic Scaling To ensure the data remains readable regardless of the asset you are trading (whether it's a major currency pair with many decimal places or a commodity with fewer), the script automatically adjusts the numbers. It detects the precision of your price feed and scales the range into a clean, standardized format that is easy to read at a glance.
3. Visual Display Once the calculation is complete, the tool performs three specific actions on your chart:
- Numerical Labeling: It places a text label at the bottom of every candle. This allows you to see the exact magnitude of price movement for that period immediately.
- Positioning: The labels are positioned relative to the lowest point of each candle, ensuring they do not overlap with the price action or the main body of the candle.
- Stylized Formatting: The values are displayed in a clean, white, bold font (Verdana), making it easy to distinguish the data from other chart elements like moving averages or trend lines.
Practical Use for Traders
By automating this calculation, the tool allows you to quickly assess market volatility. You can identify periods of extreme price expansion or consolidation without having to do any manual math. It provides an immediate visual "map" of how much ground the market is covering, helping you better understand market sentiment and price action history.
//+------------------------------------------------------------------+
//| Daily Range.mq4 |
//| Copyright © 2008, LEGRUPO |
//| http://www.legrupo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, LEGRUPO"
#property link "http://www.legrupo.com"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
double BufferRange[];
string PatternText[5000];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
// IndicatorBuffers(1);
SetIndexStyle(0, DRAW_ARROW, 0, 1);
SetIndexArrow(0, 172);
SetIndexBuffer(0,BufferRange);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectsDeleteAll();
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
double bar_range;
//----
if (counted_bars < 0) {
return(-1);
}
if (counted_bars > 0) {
counted_bars--;
}
int pos = Bars-counted_bars;
// string PatternText[5000];
for(int j = 0; j < Bars; j++)
{
PatternText[j] = "pattern-" + j;
}
while (pos>=0) {
bar_range = (High[pos] - Low[pos]);
if (Digits < 4) bar_range = bar_range * 100; else bar_range = bar_range * 10000;
ObjectCreate(PatternText[pos], OBJ_TEXT, 0, Time[pos], Low[pos]);
ObjectSet(PatternText[pos], OBJPROP_YDISTANCE, 200);
ObjectSetText(PatternText[pos], DoubleToStr(bar_range, 0), 10, "Verdana", White);
BufferRange[pos] = bar_range;
pos--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments