This technical indicator is designed to provide traders with a visual representation of market momentum by utilizing the Williams Percent Range (WPR) logic, modified specifically to account for daily timeframes.
Core Functionality
The primary purpose of this tool is to track the relationship between the high and low prices of an asset over a specific period, identifying whether the price is currently overextended in one direction or trending strongly. It produces a line on a separate window in your trading platform, ranging from -100 to 0, which helps in spotting potential "overbought" or "oversold" conditions.
Key Operational Logic
- Timeframe Awareness: The script includes a safety check to ensure it is only used on intraday charts (shorter than a Daily timeframe). It will provide an alert if you attempt to load it on a daily chart or higher, as the logic relies on sub-daily price movements.
- Dynamic Day Calculation: Rather than using a standard fixed number of candles, the script calculates the number of bars that comprise a specific number of days based on your chosen settings. It looks back at the historical data to determine exactly how many bars exist in a 24-hour period (or multiple thereof) relative to your current chart timeframe.
- Adaptive Lookback: By calculating the "bars per day" dynamically, the indicator ensures that the Williams Percent Range remains consistent regardless of whether you are viewing the market on a 15-minute, 1-hour, or 4-hour chart. This allows for a more accurate representation of daily momentum compared to standard indicators that might miscount candles during different trading sessions.
- Momentum Analysis: The final output is a smoothed line that represents the percentage of "time" spent at the top of the price range versus the bottom. When the line moves toward -100, it suggests bearish pressure; when it moves toward 0, it suggests bullish pressure.
User Experience
The tool simplifies complex time-based math into a single visual line. By automatically handling the conversion between minutes, hours, and days, it provides a reliable way to gauge market sentiment without the user having to manually adjust settings every time they switch between different chart timeframes.
//+------------------------------------------------------------------+
//| DayWPR.mq4 |
//| Copyright 2010-2015, Excstrategy |
//| http://www.ExcStrategy.ru |
//+------------------------------------------------------------------+
#property copyright "ExcStrategy"
#property link "http://www.ExcStrategy.ru"
#property version "1.1"
#property description "WPR"
#property strict
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Magenta
#property indicator_width1 1
#property indicator_minimum -100
#property indicator_maximum 0
#property indicator_level1 -20.0
#property indicator_level2 -80.0
#property indicator_levelcolor clrSilver
#property indicator_levelstyle STYLE_DOT
//----
extern int DaysForCalculation=2;
//---- buffers
double Buffer1[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(1);
//---- indicator lines
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,Buffer1);
//----
SetIndexLabel(0,"WPR");
//---
DaysForCalculation=DaysForCalculation+1;
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
if(Period()>1400)
{
Alert("Error! Period can not be greater than D1");
return(0);
}
//----
int counted_bars=IndicatorCounted();
int barsday;
bool rangeday;
datetime Time1=Time[0],Time2;
//----
if(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;
//----
for(int i=0; i<limit; i++)
{
//----
rangeday= false;
barsday = 0;
//----
Time2=Time[i]+(1440*60*DaysForCalculation);
if(Time1<Time2)
if(i<Bars-MathRound(1500/Period()))
for(int a=i; a<i+1441; a++)
{
//----
barsday++;
//----
if(TimeDayOfYear(Time[a])!=TimeDayOfYear(Time[a+1])) a=i+1442;
}
//----
Buffer1[i]=iWPR(NULL,0,barsday,i);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments