VininI_MV_MA_WPR(v1)
Download scriptThis custom indicator is designed to provide traders with a visual representation of market momentum and price positioning by combining two distinct analytical tools: the Williams Percent Range (WPR) and a Moving Average (MA). It provides a specialized view of how price fluctuates relative to its recent range, smoothed out to identify more reliable trends.
Core Logic and Functionality
1. Data Source Integration The script is configured to track a specific currency pair (defaulting to GBPUSD). It retrieves price data from the market to calculate two primary layers of information: the raw momentum of the price and a smoothed version of that momentum.
2. The Williams Percent Range (WPR) Transformation The underlying engine uses the Williams Percent Range, which is a momentum indicator that measures the relationship between the current closing price and the high/low range over a specific period.
- Standardization: In its raw form, WPR typically fluctuates between 0 and -100. This script applies a mathematical adjustment to shift these values into a different scale (centered around a different baseline), making it easier to visualize relative strengths in a separate window on the chart.
3. Trend Smoothing via Moving Average To prevent the visual data from being too "noisy" or erratic, the script takes the processed WPR data and applies a Moving Average.
- This calculates the average value of the momentum over a user-defined period (such as the last 5 units).
- By doing this, the indicator filters out minor price fluctuations, allowing the user to see the broader "flow" of the market's momentum more clearly.
4. Performance Optimization The logic includes specific commands to manage how much historical data is processed at one time. By setting a limit on the number of bars calculated, the script ensures that it remains responsive and does not consume excessive computing power, while still providing accurate real-time updates for the current market price.
Visual Output
Instead of appearing directly on the main price chart (which can clutter your view of candles), this indicator appears in a separate window at the bottom of your screen. It provides a distinct line that reflects the "smoothed" momentum of the chosen currency pair, helping traders identify whether the market is trending strongly in one direction or if it is becoming overextended.
//+------------------------------------------------------------------+
//| VininI_MV_MA_WPR_v1.mq4 |
//| Victor Nicolaev aka Vinin|
//| vinin@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Ñopyright 2008. Victor Nicolaev aka Vinin"
#property link "e-mail: vinin@mail.ru"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Aqua
#property indicator_level1 0
#property indicator_level2 60
#property indicator_level3 -60
#property indicator_maximum 100
#property indicator_minimum -100
//---- input parameters
extern string WPR_Symbol="GBPUSD";
extern int MA_Period=5;
extern int MA_Mode=0;
extern int WPR_Period= 14;
extern int Limit=1440;
double WPR[];
double MA[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init() {
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_LINE);
SetIndexDrawBegin(0,WPR_Period+MA_Period);
SetIndexBuffer(0,MA);
SetIndexBuffer(1,WPR);
IndicatorShortName(WPR_Symbol+"(WPR,"+WPR_Period+")");
SetIndexLabel(0,WPR_Symbol+"(WPR)");
return(0); }
//+------------------------------------------------------------------+
int start() {
static int TimeWPR=-1;
int limit;
int counted_bars=IndicatorCounted();
int i, CurrentTime, WPRPos;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
if (limit>Limit && Limit>0) limit = Limit;
if (TimeWPR>0) limit+=iBarShift(WPR_Symbol,Period(),TimeWPR);
for (i = limit;i>=0;i--){
CurrentTime=Time[i];
WPRPos=iBarShift(WPR_Symbol,Period(),CurrentTime);
if (iTime(WPR_Symbol,Period(),WPRPos)<CurrentTime) WPRPos++;
WPR[i] = (iWPR(WPR_Symbol,Period(),WPR_Period,WPRPos)+50.0)*2.0;
}
for (i = limit;i>=0;i--) MA[i] = iMAOnArray(WPR,0,MA_Period,0,MA_Mode,i);
TimeWPR=iTime(WPR_Symbol,Period(),0);
return(0);
}// int start()
Comments