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.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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