WPR_JMA-HLOC_v1

Download script
Author: Copyright � 2005, MetaQuotes Software Corp. & Henry White

This script is a specialized technical analysis tool designed to enhance the standard Williams %R (Williams Percent Range) oscillator. While the traditional Williams %R is primarily used to identify overbought and oversold conditions based on closing prices, this modified version provides a much deeper look into price action by incorporating multi-point analysis and advanced smoothing techniques.

Core Logic Overview

The script functions by evaluating where the current market price sits relative to its highest highs and lowest lows over a specific period of time. Instead of looking at just one data point (the closing price), it calculates four distinct perspectives:

  • Closing Price Position: Where the price ended compared to the range.
  • Opening Price Position: Where the price started compared to the range.
  • High Price Position: How close the peak was to the overall range.
  • Low Price Position: How close the bottom was to the overall range.

Key Enhancements

1. JMA Smoothing (Jurik Moving Average) The script applies a specialized smoothing algorithm known as the Jurik Moving Average (JMA). In non-technical terms, this acts like a "high-definition" filter. It removes the jagged, noisy movements of standard price charts to reveal smoother trends while remaining highly responsive to actual price changes—minimizing the "lag" that often plagues other types of moving averages.

2. Multi-Level Data Processing Unlike standard oscillators that provide a single line, this script calculates four separate data streams for the prices mentioned above (Close, Open, High, and Low). By processing these simultaneously, the tool provides a comprehensive view of the "geography" of the current price movement.

3. Comparative Analysis (The Differences) Beyond just showing where the price is, the script performs mathematical calculations to find the difference between these various points. It generates four specific comparison metrics:

  • The difference between the Close and Open positions.
  • The difference between the High and Low positions.
  • The difference between the High and Open positions.
  • The difference between the Low and Close positions (with an inverted calculation).

Visual Output and Utility

By translating these complex interactions into visual lines and a histogram, the tool allows users to see not just where the price is currently sitting, but how the "body" of the price candles (the relationship between opens, highs, lows, and closes) is reacting within the larger trend. This provides a more nuanced perspective on momentum and price exhaustion than a standard oscillator could offer alone.

Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
WPR_JMA-HLOC_v1
//+------------------------------------------------------------------+
//|                                      Williams’ Percent Range.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
// Ê ñòàíäàðòíîìó WPR äîáàâëåíî JMA-ñãëàæèâàíèå 
// Âûâåäåíû çíà÷åíèÿ íå òîëüêî ïî CLOSE, íî è ïî îñòàëüíûì öåíîâûì óðîâíÿì (High, Low, Open)
// Ïóíêòèðîì âûâåäåíû ðàçíîñòè ìåæäó WPR (HLOC)
// Ïðîèçâåäåíî èíâåðòèðîâàíèå äèàïàçîíà
#property copyright "Copyright © 2005, MetaQuotes Software Corp. & Henry White"
#property link      "http://www.metaquotes.net/"
//----
#property indicator_separate_window
#property indicator_minimum -20
#property indicator_maximum 120
#property indicator_level1 100
#property indicator_level2 80
#property indicator_level3 20

#property indicator_buffers 8
#property indicator_color1 DodgerBlue
#property indicator_color2 Red
#property indicator_color3 Yellow
#property indicator_color4 Aqua
#property indicator_color5 Lime
#property indicator_color6 DeepPink
#property indicator_color7 BlueViolet
#property indicator_color8 White
#property indicator_width4  1
#property indicator_width5  1
#property indicator_style5  2       // 
#property indicator_style6  2       // 
#property indicator_style7  2       // 
#property indicator_style8  2       // 


extern int ExtWPRPeriod = 80;
extern int Phase  = 100;         // ïàðàìåòð JMA ñãëàæèâàíèÿ, èçìåíÿþùèéñÿ â ïðåäåëàõ -100 ... +100, âëèÿåò íà êà÷åñòâî ïåðåõîäíîãî ïðîöåññà; 
extern int JMAPeriod = 16;       // ïåðèîä ñãëàæèâàíèÿ

double ExtWPRBufferC[];
double ExtWPRBufferO[];
double ExtWPRBufferH[];
double ExtWPRBufferL[];
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];

#include <JJMASeries.mqh> 

int init()
  {
   string sShortName;
   
   if(JJMASeriesResize(4) != 4)   return(-1);
   
   IndicatorBuffers(8);

   SetIndexBuffer(0, ExtWPRBufferC);
   SetIndexBuffer(1, ExtWPRBufferO);
   SetIndexBuffer(2, ExtWPRBufferH);
   SetIndexBuffer(3, ExtWPRBufferL);
   SetIndexBuffer(4, Buffer1);
   SetIndexBuffer(5, Buffer2);
   SetIndexBuffer(6, Buffer3);
   SetIndexBuffer(7, Buffer4);

   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexStyle(2, DRAW_LINE);
   SetIndexStyle(3, DRAW_LINE);
   SetIndexStyle(4, DRAW_LINE);
   SetIndexStyle(5, DRAW_LINE);
   SetIndexStyle(6, DRAW_LINE);
   SetIndexStyle(7, DRAW_LINE);

   sShortName="WPR_JMA(" + (string)ExtWPRPeriod + ") ";
   IndicatorShortName(sShortName);
   SetIndexLabel(0, sShortName+"Close");
   SetIndexLabel(1, sShortName+"Open");
   SetIndexLabel(2, sShortName+"High");
   SetIndexLabel(3, sShortName+"Low");
   SetIndexLabel(4, sShortName+"CO");  // SUMM

   SetIndexLabel(5, sShortName+"HL");
   SetIndexLabel(6, sShortName+"HO");
   SetIndexLabel(7, sShortName+"LC");

   SetIndexDrawBegin(0, ExtWPRPeriod);
   SetIndexDrawBegin(1, ExtWPRPeriod);
   SetIndexDrawBegin(2, ExtWPRPeriod);
   SetIndexDrawBegin(3, ExtWPRPeriod);
   SetIndexDrawBegin(4, ExtWPRPeriod);
   SetIndexDrawBegin(5, ExtWPRPeriod);
   SetIndexDrawBegin(6, ExtWPRPeriod);
   SetIndexDrawBegin(7, ExtWPRPeriod);

   return(0);
  }
  
  
//+------------------------------------------------------------------+
//| Williams’ Percent Range                                          |
//+------------------------------------------------------------------+
int start()
  {
   int i, counted_bars, MaxBar, reset, limit, scale;  
   double Diff;

   if(Bars < ExtWPRPeriod) return(0);
   counted_bars = IndicatorCounted();
   if(counted_bars < 0) return (-1);
   if(counted_bars > 0) counted_bars--;

   MaxBar=Bars-1; 
   limit=Bars-counted_bars-1;
   
   for(i=limit; i>=0; i--)  {
      double dMaxHigh = High[Highest(NULL, 0, MODE_HIGH, ExtWPRPeriod, i)];
      double dMinLow = Low[Lowest(NULL, 0, MODE_LOW, ExtWPRPeriod, i)];
      Diff = dMaxHigh - dMinLow;
      if(!CompareDouble(Diff, 0.0))  {
           ExtWPRBufferC[i] = -100*(dMaxHigh - Close[i])/ (Diff) + 100;
           ExtWPRBufferO[i] = -100*(dMinLow  - Open[i]) / (Diff);
           ExtWPRBufferH[i] = -100*(dMinLow  - High[i]) / (Diff);
           ExtWPRBufferL[i] = -100*(dMaxHigh - Low[i] ) / (Diff) + 100;
      } else {
           ExtWPRBufferC[i] = 0;
           ExtWPRBufferO[i] = 0;
           ExtWPRBufferH[i] = 0;
           ExtWPRBufferL[i] = 0;
      }     

      ExtWPRBufferC[i] = JJMASeries(0,0,MaxBar,limit,Phase,JMAPeriod,ExtWPRBufferC[i],i,reset); 
      ExtWPRBufferO[i] = JJMASeries(1,0,MaxBar,limit,Phase,JMAPeriod,ExtWPRBufferO[i],i,reset); 
      ExtWPRBufferH[i] = JJMASeries(2,0,MaxBar,limit,Phase,JMAPeriod,ExtWPRBufferH[i],i,reset); 
      ExtWPRBufferL[i] = JJMASeries(3,0,MaxBar,limit,Phase,JMAPeriod,ExtWPRBufferL[i],i,reset); 
      
      scale = 4;
      Buffer1[i] = (ExtWPRBufferC[i] - ExtWPRBufferO[i])*scale;
      Buffer2[i] = (ExtWPRBufferH[i] - ExtWPRBufferL[i])*scale;
      Buffer3[i] = (ExtWPRBufferH[i] - ExtWPRBufferO[i])*scale;
      Buffer4[i] = (ExtWPRBufferL[i] - ExtWPRBufferC[i])*(-scale);
   }

   return(0);
  }
  

bool CompareDouble(double Number1, double Number2)
{
    bool Compare = NormalizeDouble(Number1 - Number2, 8) == 0;
    return(Compare);
} 

Comments