can you help me?why there are many mistakes in the code?

 
this is to calculate SMMA:
for(j=0;j<Bars;j++)
{
for(i=0,sum=0;i<ma_period;i++)
{
sum=sum+Close[j+i];
// buffer[j]=(sum-sum/ma_period+Close[j+i])/ma_period;
}
buffer[j]=(sum-sum/ma_period+Close[j])/ma_period;
}




this is to calculate LWMA

for(j=0;j<Bars;j++)
{
for(i=0,sum=0,sum1=0;i<ma_period;i++)
{
sum=sum+Close[j+i];
sum1=sum1+Close[j+i]*(j+i);
// buffer[j]=sum/ma_period;
}
buffer[j]=sum1/sum;
}


and how to calculate EMA?

and what's the differences between IndicatorCounted adn Bars? i don't understand exactly.
does anyone can teach me through msn or icq?
thank you very much
 
deuxmille:

if you wanted SMMA here is how it should be done :

int i,j;

double sum;

//----

for(j=Bars-ma_period;j>=0 ;j--)

{

if(Bars-ma_period == j)

for(i=0,sum=0;i<ma_period;i++)

sum+=Close[j-i];

else

sum = buffer[j+1]*ma_period - buffer[j+1] +Close[j];

buffer[j]=sum/ma_period;

}

for other ones check the UserGuide in the trader and it will tell you.

here you will find the definition of IndicatorCounted it is the unchanged Bars

https://docs.mql4.com/customind/IndicatorCounted

Hazem.

Reason: