Download MetaTrader 5
To add comments, please log in or register
Do you have Mac OS? Find out how to install MetaTrader on it!
Mimi
499
Mimi 2016.07.01 05:04 

I have this following code volume average. But its showing wrong data & data is changing in every tick into really big larger value. Not sure what is the problem here.

int A = 0, HTP[2000];
for(int k=0;k<=13;k++)
  {
 startbarindex[k] = iBarShift(P[k],PERIOD_M1,(iTime(P[k],PERIOD_D1,Bar)));
 
 for(int p = 1; p <= startbarindex[k]; p++)
 { 
 HTP[p] = (int) iVolume(P[k],PERIOD_M1,p);
 A += HTP[p];
 }
 Average[k] = (int) A / startbarindex[k];
}

 Thank you in advance. 

whroeder1
13597
whroeder1 2016.07.01 13:35  
  1. Set A to zero inside the k loop.
  2. Unless you use HTP[] elsewhere, remove it and sum directly to A.
Blahtech Limited
2814
James Cater 2016.07.01 14:39  

iVolume returns a long, so you should change A to a long and remove the first cast (I would also change the Average array to be long and remove the second cast)


for(int k = 0; k <= 13; k++)
{
   long A = 0;

   startbarindex[k] = iBarShift(P[k], PERIOD_M1, iTime(P[k], PERIOD_D1, Bar));
 
   for(int p = 1; p <= startbarindex[k]; p++)
   { 
      A += iVolume(P[k], PERIOD_M1, p);
   }
   Average[k] = A / startbarindex[k];
}
Mimi
499
Mimi 2016.07.02 05:22  
jamescater:

iVolume returns a long, so you should change A to a long and remove the first cast (I would also change the Average array to be long and remove the second cast)




Thank you both WHRoeder & jamescater

Your suggestion worked.

/
To add comments, please log in or register