WPR_v2
Download scriptThis technical indicator, known as the Williams’ Percent Range (WPR), is designed to help traders identify whether a financial asset is currently overbought or oversold. Rather than looking at simple price action alone, it measures where the current closing price sits relative to the highest and lowest prices reached over a specific timeframe.
How the Logic Works
The tool operates by analyzing a fixed window of recent price data (the "period"), which can be customized by the user. Here is the step-by-step breakdown of its internal logic:
- Scanning for Extremes: For every point on the chart, the script looks back at a predetermined number of previous candles to identify two key values: the absolute highest price reached and the absolute lowest price reached during that period.
- Calculating the Range: It then determines the total "distance" between that high and low point. This represents the total trading range for that specific timeframe.
- Positioning the Current Price: The script compares the current closing price against that maximum high. It calculates what percentage of the total range the current price has covered from the bottom up.
- Converting to a Scale: Finally, the result is converted into a percentage scale ranging from 0 to -100. This allows traders to see how "stretched" the price is.
How to Interpret the Results
The indicator appears in a separate window below your main chart as a line graph. Because it measures the position of the price within its recent range, it provides a visual cue for market momentum:
- Oversold Conditions: When the line moves toward the lower end of the scale (approaching -80), it suggests that the price has dropped significantly relative to its recent highs, potentially indicating that the asset is "oversold" and might be due for a bounce.
- Overbought Conditions: When the line moves toward the upper end of the scale (approaching 0), it suggests that the price has climbed significantly relative to its recent lows, potentially indicating that the asset is "overbought" and may be reaching a point of exhaustion.
In short, this script acts as a momentum gauge, helping you visualize whether the current market move is becoming extreme based on historical highs and lows.
//+------------------------------------------------------------------+
//| Williams Percent Range.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_separate_window
#property indicator_minimum -100
#property indicator_maximum 0
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
#property indicator_level1 -20
#property indicator_level2 -80
//---- input parameters
extern int ExtWPRPeriod=14;
//---- buffers
double ExtWPRBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string sShortName;
//---- indicator buffer mapping
SetIndexBuffer(0,ExtWPRBuffer);
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
//---- name for DataWindow and indicator subwindow label
sShortName="%R("+ExtWPRPeriod+")";
IndicatorShortName(sShortName);
SetIndexLabel(0,sShortName);
//---- first values aren't drawn
SetIndexDrawBegin(0,ExtWPRPeriod);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Williams Percent Range |
//+------------------------------------------------------------------+
int start()
{
int i,nLimit,nCountedBars;
//---- insufficient data
if(Bars<=ExtWPRPeriod) return(0);
//---- bars count that does not changed after last indicator launch.
nCountedBars=IndicatorCounted();
//----Williams Percent Range calculation
i=Bars-ExtWPRPeriod-1;
if(nCountedBars>ExtWPRPeriod)
i=Bars-nCountedBars-1;
while(i>=0)
{
double dMaxHigh=High[Highest(NULL,0,MODE_HIGH,ExtWPRPeriod,i)];
double dMinLow=Low[Lowest(NULL,0,MODE_LOW,ExtWPRPeriod,i)];
ExtWPRBuffer[i]=-100*(dMaxHigh-Close[i])/(dMaxHigh-dMinLow);
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments