PdfMA MACD Indicator For MT5
The PdfMA MACD Indicator For MT5 displays a uniquely customized MACD indicator that is calculated as the difference between a fast and a slow Probability Density Function (PDF) based Moving Averages (MA). The PDF based MA falls in to the category of weighted Moving Averages. It utilizes probability density function to calculate the price weights. This makes it similar in nature to a number of digital filters. The MACD signal line is also computed as a PDF based MA.
The PdfMA MACD Indicator For MT5 can be analyzed, interpreted, and employed like a conventional MACD indicator.
Installing the PdfMA MACD Indicator For MT5
After you downloaded the indicator via the form above you need to unzip the zip-file. Then you need to copy the file PdfMA MACD.mq5 into the folder MQL5\Indicators of your MT5 installation. After that please restart MT5 and then you will be able to see the indicator in the list of indicators.
Parameters of the PdfMA MACD Indicator For MT5
The PdfMA MACD Indicator For MT5 has 5 parameters to configure.
input int inpFastPeriod = 12; // Fast period
input int inpSlowPeriod = 26; // Slow period
input int inpSignalPeriod = 9; // Signal period
input double inpVariance = 1; // Variance
input ENUM_APPLIED_PRICE inpPrice = PRICE_CLOSE; // Price
Buffers of the PdfMA MACD Indicator For MT5
The PdfMA MACD Indicator For MT5 provides 2 buffers.
SetIndexBuffer(0,macd ,INDICATOR_DATA);
SetIndexBuffer(1,signal,INDICATOR_DATA);
Main Parts Of The Code
int OnCalculate(const int rates_total,const int prev_calculated,const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
int i= prev_calculated-1; if (i lt 0) i=0; for (; i lt rates_total && !_StopFlag; i++)
{
double _price; _setPrice(inpPrice,_price,i);
macd[i] = iPdfMaFast.calculate(_price,i)-iPdfMaSlow.calculate(_price,i);
signal[i] = iPdfMaSignal.calculate(macd[i],i);
}
return(i);
}
//------------------------------------------------------------------
// Custom function(s)
//------------------------------------------------------------------
//
//---
//
class cPdfMa
{
private :
int m_period;
int m_arraysize;
double m_work[];
double m_coeffs[];
double m_coeffw;
public :
cPdfMa() { init(1,1,0); }
~cPdfMa() {};
//
//
//
void init(int period, double variance) { init(period,variance,0); }
void init(int period, double variance, double mean)
{
m_period = (period gt 1) ? period : 1;
m_arraysize = m_period+32;
m_coeffw = 0;
ArrayResize(m_work,m_arraysize); ArrayInitialize(m_work,0);
ArrayResize(m_coeffs,m_period);
//
//---
//
#define maxx 3.5
#define pdf(_x,_variance,_mean) (1.0/MathSqrt(2*M_PI*_variance*_variance)*MathExp(-((_x-_mean)*(_x-_mean))/(2*_variance*_variance)))
if (variance lt 0.01) variance = 0.01;
if (mean lt -1) mean = -1;
if (mean gt 1) mean = 1;
if (m_period gt 1)
{
double step = maxx/(m_period-1);
for(int i=0; i lt m_period; i++)
{
m_coeffs[i] = pdf(i*step,variance,mean*maxx);
m_coeffw += m_coeffs[i];
}
}
else { m_coeffs[0] = m_coeffw = 1; }
#undef pdf #undef maxx
}
double calculate(double price, int i)
{
int _indC = (i)%m_arraysize; m_work[_indC] = price;
double _avg = 0;
for (int k=0; k lt m_period; k++,_indC--)
{
if (_indC lt 0) _indC += m_arraysize;
_avg += m_work[_indC]*m_coeffs[k];
}
return(_avg/m_coeffw);
}
};
cPdfMa iPdfMaFast,iPdfMaSlow,iPdfMaSignal;
//------------------------------------------------------------------