0
Views
0
Downloads
0
Favorites
XPercentR-PCR
/*
* For the indicator to work, place the
* SmoothAlgorithms.mqh
* in the directory: MetaTrader\\MQL5\Include
*/
//+------------------------------------------------------------------+
//| XPercentR-PCR.mq5 |
//| Copyright © 2006, Scorpion@fxfisherman.com |
//| http://www.fxfisherman.com |
//+------------------------------------------------------------------+
//---- author of the indicator
#property copyright "Copyright © 2006, Scorpion@fxfisherman.com"
//---- link to the website of the author
#property link "http://www.fxfisherman.com"
//---- indicator version number
#property version "1.00"
//---- drawing indicator in a separate window
#property indicator_separate_window
//----two buffers are used for calculation of drawing of the indicator
#property indicator_buffers 2
//---- one plot is used
#property indicator_plots 1
//+-----------------------------------+
//| Declaration of constants |
//+-----------------------------------+
#define RESET 0 // the constant for getting the command for the indicator recalculation back to the terminal
//+-----------------------------------+
//| Filling drawing parameters |
//+-----------------------------------+
//---- drawing indicator as a filling between two lines
#property indicator_type1 DRAW_FILLING
//---- Teal and DeepPink colors are used as the indicator filling colors
#property indicator_color1 Teal,DeepPink
//---- displaying the indicator label
#property indicator_label1 "XPercentR-PCR"
//+-----------------------------------+
//| CXMA class description |
//+-----------------------------------+
#include <SmoothAlgorithms.mqh>
//+-----------------------------------+
//---- declaration of the CXMA class variables from the SmoothAlgorithms.mqh file
CXMA UpXMA,DnXMA;
//+-----------------------------------+
//| Declaration of enumerations |
//+-----------------------------------+
enum Applied_price_ //Type od constant
{
PRICE_CLOSE_ = 1, //Close
PRICE_OPEN_, //Open
PRICE_HIGH_, //High
PRICE_LOW_, //Low
PRICE_MEDIAN_, //Median Price (HL/2)
PRICE_TYPICAL_, //Typical Price (HLC/3)
PRICE_WEIGHTED_, //Weighted Close (HLCC/4)
PRICE_SIMPL_, //Simpl Price (OC/2)
PRICE_QUARTER_, //Quarted Price (HLOC/4)
PRICE_TRENDFOLLOW0_, //TrendFollow_1 Price
PRICE_TRENDFOLLOW1_ //TrendFollow_2 Price
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
/*enum Smooth_Method - the enumeration is declared in the SmoothAlgorithms.mqh file
{
MODE_SMA_, //SMA
MODE_EMA_, //EMA
MODE_SMMA_, //SMMA
MODE_LWMA_, //LWMA
MODE_JJMA, //JJMA
MODE_JurX, //JurX
MODE_ParMA, //ParMA
MODE_T3, //T3
MODE_VIDYA, //VIDYA
MODE_AMA, //AMA
}; */
//+-----------------------------------+
//| enumeration declaration |
//+-----------------------------------+
enum WIDTH
{
Width_1=1, //1
Width_2, //2
Width_3, //3
Width_4, //4
Width_5 //5
};
//+-----------------------------------+
//| enumeration declaration |
//+-----------------------------------+
enum STYLE
{
SOLID_,//Solid line
DASH_,//Dashed line
DOT_,//Dotted line
DASHDOT_,//Dot-dash line
DASHDOTDOT_ //Dot-dash line with double dots
};
//+----------------------------------------------+
//| Indicator input parameters |
//+----------------------------------------------+
input uint HL_Period=55;
//----
input Smooth_Method SmoothMethod=MODE_JJMA; //smoothing method
input uint SmoothLength=3; //smoothing depth
input int SmoothPhase=100; //smoothing parameter,
// for JJMA that can change withing the range -100 ... +100. It impacts the quality of the intermediate process of smoothing;
//----
input uint UpLevel=80; // overbought level
input uint DnLevel=20; // oversold level
input color UpLevelsColor=Purple; //overbought level color
input color DnLevelsColor=Purple; //oversold level color
input STYLE Levelstyle=DASH_; //levels style
input WIDTH LevelsWidth=Width_1; //levels width
//+----------------------------------------------+
//---- declaration of dynamic arrays that further
//---- will be used as indicator buffers
double BullsBuffer[];
double BearsBuffer[];
//---- declaration of the integer variables for the start of data calculation
int min_rates_total,min_rates_;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//---- setting up alerts for unacceptable values of external parameters
UpXMA.XMALengthCheck("SmoothLength", SmoothLength);
UpXMA.XMAPhaseCheck("SmoothPhase", SmoothPhase, SmoothMethod);
//---- Initialization of variables of the start of data calculation
min_rates_=int(HL_Period);
min_rates_total=min_rates_+UpXMA.GetStartBars(SmoothMethod,SmoothLength,SmoothPhase);
//---- transformation of the dynamic array BullsBuffer into an indicator buffer
SetIndexBuffer(0,BullsBuffer,INDICATOR_DATA);
//---- performing shift of the beginning of counting of drawing the indicator 1 by min_rates_total
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
//---- indexing elements in the buffer as in timeseries
ArraySetAsSeries(BullsBuffer,true);
//---- transformation of the BearsBuffer dynamic array into an indicator buffer
SetIndexBuffer(1,BearsBuffer,INDICATOR_DATA);
//---- performing shift of the beginning of counting of drawing the indicator 2 by min_rates_total
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);
//---- indexing elements in the buffer as in timeseries
ArraySetAsSeries(BearsBuffer,true);
//---- initializations of variable for indicator short name
string shortname="XPercentR-PCRA";
//--- creation of the name to be displayed in a separate sub-window and in a pop up help
IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//---- determination of accuracy of displaying the indicator values
IndicatorSetInteger(INDICATOR_DIGITS,0);
//---- lines drawing parameters
IndicatorSetInteger(INDICATOR_LEVELS,2);
IndicatorSetDouble(INDICATOR_LEVELVALUE,0,UpLevel);
IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,UpLevelsColor);
IndicatorSetInteger(INDICATOR_LEVELSTYLE,0,Levelstyle);
IndicatorSetInteger(INDICATOR_LEVELWIDTH,0,LevelsWidth);
IndicatorSetDouble(INDICATOR_LEVELVALUE,1,DnLevel);
IndicatorSetInteger(INDICATOR_LEVELCOLOR,1,DnLevelsColor);
IndicatorSetInteger(INDICATOR_LEVELSTYLE,1,Levelstyle);
IndicatorSetInteger(INDICATOR_LEVELWIDTH,1,LevelsWidth);
//----
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(
const int rates_total, // amount of history in bars at the current tick
const int prev_calculated,// amount of history in bars at the previous tick
const datetime &time[],
const double &open[],
const double& high[], // price array of maximums of price for the calculation of indicator
const double& low[], // price array of price lows for the indicator calculation
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[]
)
{
//---- checking the number of bars to be enough for calculation
if(rates_total<min_rates_total) return(RESET);
//---- declaration of local variables
int limit,bar,bar1,maxbar;
double h,l,p,Up,Dn,d;
//---- calculation of maxbar initial index for the XMASeries() function
maxbar=rates_total-1-min_rates_;
//---- Calculate the "limit" starting number for loop of bars recalculation
if(prev_calculated>rates_total || prev_calculated<=0)// checking for the first start of calculation of an indicator
limit=maxbar; // starting index for calculation of all bars
else limit=rates_total-prev_calculated; // starting index for calculation of new bars
//---- indexing elements in arrays as timeseries
ArraySetAsSeries(low,true);
ArraySetAsSeries(high,true);
ArraySetAsSeries(close,true);
//---- main cycle of calculation of the indicator
for(bar=limit; bar>=0 && !IsStopped(); bar--)
{
bar1=bar+1;
p= close[bar];
h=high[ArrayMaximum(high,bar1,HL_Period)];
l=low [ArrayMinimum(low, bar1,HL_Period)];
d=h-l;
if(d)
{
Dn = ((h-p)/d)*100;
Up = ((p-l)/d)*100;
}
else
{
Up=0;
Dn=0;
}
BullsBuffer[bar]=UpXMA.XMASeries(maxbar,prev_calculated,rates_total,SmoothMethod,SmoothPhase,SmoothLength,Up,bar,true);
BearsBuffer[bar]=DnXMA.XMASeries(maxbar,prev_calculated,rates_total,SmoothMethod,SmoothPhase,SmoothLength,Dn,bar,true);
}
//----
return(rates_total);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---