WPR_JMA-HLOC

Author: Copyright � 2005, MetaQuotes Software Corp. & Henry White
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
WPR_JMA-HLOC
//+------------------------------------------------------------------+
//|                                      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(" + 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, nLimit, 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

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---