Price_Range
Download scriptThis technical indicator is designed to help traders visualize and quantify the volatility and price movement of a specific asset over a fixed period of time. Rather than looking at raw prices, it focuses on calculating the "distance" traveled by the price relative to a starting point.
How It Works
The logic operates by analyzing a user-defined window of historical data (determined by the PR_Period setting). For every candle on your chart, the script performs the following steps:
- Establishing a Baseline: The indicator identifies the "Opening Price" at the beginning of the chosen period. This serves as the zero-point or reference anchor for all subsequent calculations.
- Identifying Extremes: It automatically scans back through the historical data within that period to find the highest and lowest price points reached during that timeframe.
- Calculating Deviations: The tool then calculates three specific values based on how far the market moved from the baseline:
- High Movement: How far the price climbed upward from the starting point to its peak.
- Low Movement: How far the price dropped downward from the starting point to its trough.
- Closing Movement: The final distance between the starting point and where the price actually finished at the end of the period.
Visual Representation
Instead of appearing on your main price chart, this indicator is displayed in a separate window below it. It plots three distinct lines:
- The High Line (Green): Tracks the magnitude of the upward movement.
- The Close Line (Blue): Tracks the net displacement of the price.
- The Low Line (Red): Tracks the magnitude of the downward movement.
Key Benefit for Traders
By converting these price movements into numerical values based on "Points," the indicator removes the visual noise of a standard chart and replaces it with clear, measurable data. It allows you to see at a glance whether a specific period was characterized by massive swings (high volatility), steady growth, or significant pullbacks, regardless of the actual price level of the asset.
//+------------------------------------------------------------------+
//| Price Range.mq4 |
//| Grigori Minassian |
//+------------------------------------------------------------------+
#property copyright "Grigori Minassian"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Green
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_width1 1
#property indicator_width3 1
double ChangeHigh[];
double ChangeClose[];
double ChangeLow[];
extern int PR_Period = 60;
int init()
{
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_LINE);
SetIndexStyle(2, DRAW_LINE);
SetIndexBuffer(0, ChangeHigh);
SetIndexBuffer(1, ChangeClose);
SetIndexBuffer(2, ChangeLow);
IndicatorDigits(Digits + 1);
IndicatorShortName("Price Range(" + PR_Period + ")");
SetIndexLabel(0, "High");
SetIndexLabel(1, "Close");
SetIndexLabel(2, "Low");
return(0);
}
double price_change_high = 0;
double price_change_low = 0;
double price_change_close = 0;
void ComputePriceRange(int period, int shift)
{
int high_shift = iHighest(Symbol(), 0, MODE_CLOSE, period, shift);
int low_shift = iLowest(Symbol(), 0, MODE_CLOSE, period, shift);
double price_open = iClose(Symbol(), 0, period + shift);
double price_high = iClose(Symbol(), 0, high_shift);
double price_low = iClose(Symbol(), 0, low_shift);
double price_close = iClose(Symbol(), 0, shift);
price_change_high = (price_high - price_open) / Point;
price_change_low = (price_low - price_open) / Point;
price_change_close = (price_close - price_open) / Point;
}
int start()
{
int i, limit;
int counted_bars=IndicatorCounted();
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(i = 0; i < limit; i++)
{
ComputePriceRange(PR_Period, i);
ChangeHigh[i] = price_change_high;
ChangeClose[i] = price_change_close;
ChangeLow[i] = price_change_low;
}
return(0);
}
Comments