I resume this post to ask if someone who knows the MT4 language can help me insert in the classic moving average vidya a further smoothing with the classic moving averages Simple, Exponential, Smoothed, Linear Weighted.
I tried but my programming level is at the beginning, I put the code of the classic Vidya.
Thanks to whoever intervenes
//+------------------------------------------------------------------+
//| Vidya Prova.mq4 |
//| Io |
//|
https://www.mql5.com |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 clrMagenta
#property indicator_width1 0
#property strict
//
//
//
//
//
extern int CmoPeriod1 = 15; // CMO period
extern int SmoothPeriod1 = 15; // Smoothing period
extern int MA = 15; // Smoothing SMA
extern ENUM_APPLIED_PRICE Price1 = PRICE_CLOSE; // Price
double val[],valda[],valdb[],slope[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int init()
{
IndicatorBuffers(4);
SetIndexBuffer(0,val);
SetIndexBuffer(1,valda);
SetIndexBuffer(2,valdb);
SetIndexBuffer(3,slope);
return(0);
}
//
//
//
//
//
int start()
{
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
int limit = MathMin(Bars-counted_bars,Bars-1);
//
//
//
//
//
if (slope[limit]==-1) CleanPoint(limit,valda,valdb);
for(int i=limit; i>=0; i--)
{
val
= iVidya(iMA(NULL,0,1,0,MODE_SMA,Price1,i),CmoPeriod1,SmoothPeriod1,i,0);
valda = EMPTY_VALUE;
valdb = EMPTY_VALUE;
slope = (i<Bars-1) ? (val>val[i+1]) ? 1 : (val<val[i+1]) ? -1 : slope[i+1] : 0;
if (slope==-1) PlotPoint(i,valda,valdb,val);
}
return(0);
}
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
#define _vidyaInstances 1
#define _vidyaInstancesSize 2
double vidya_work[][_vidyaInstances*_vidyaInstancesSize];
#define vidya_price 0
#define vidya_value 1
double iVidya(double price, int cmoPeriods, int smoothPeriod, int i, int instanceNo=0)
{
if (ArrayRange(vidya_work,0)!=Bars) ArrayResize(vidya_work,Bars); int r = Bars-i-1; int s = instanceNo*_vidyaInstancesSize;
//
//
//
//
//
vidya_work[r][s+vidya_price] = price;
double sumUp = 0;
double sumDo = 0;
for (int j=0; j < cmoPeriods && (r-j-1)>=0; j++)
{
double diff = vidya_work[r-j][s+vidya_price]-vidya_work[r-j-1][s+vidya_price];
if (diff > 0)
sumUp += diff;
else sumDo -= diff;
}
double k = ((sumUp+sumDo)!=0) ? MathAbs((sumUp-sumDo)/(sumUp+sumDo)): 1;
vidya_work[r][s+vidya_value] = (r>0) ? vidya_work[r-1][s+vidya_value]+(k*2.00/(1.00+MathMax(smoothPeriod,1)))*(vidya_work[r][s+vidya_price]-vidya_work[r-1][s+vidya_value]) : price;
return(vidya_work[r][s+vidya_value]);
}
//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//
void CleanPoint(int i,double& first[],double& second[])
{
if ((second != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE))
second[i+1] = EMPTY_VALUE;
else
if ((first != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE))
first[i+1] = EMPTY_VALUE;
}
//
//
//
//
//
void PlotPoint(int i,double& first[],double& second[],double& from[])
{
if (i>=Bars-2) return;
if (first[i+1] == EMPTY_VALUE)
{
if (first[i+2] == EMPTY_VALUE)
{ first = from[i]; first[i+1] = from[i+1]; second[i] = EMPTY_VALUE; }
else { second[i] = from[i]; second[i+1] = from[i+1]; first[i] = EMPTY_VALUE; }
}
else { first[i] = from[i]; second[i] = EMPTY_VALUE; }
}