Trouble with For Loops inside Custom Function

 

Hi

 

Can somebody please help me with this consistent issue i have with executing a For loop inside a function. The same code in start() works ok but when its in a custom function i always get zero values for the variables.

The functions intention is to determine when the Bollinger bands contract by checking the current StdDev MA against the Highest Std Dev MA of 12 periods ago.

 

 
//========================================================================================
//  Bollinger Contraction
//========================================================================================

bool BolContraction()
{
   double HighVal=0;
   double Val[12];
   
   for (int i = 12; i > 0; i--)
   {
   
   Val[i]=iStdDev(NULL,0,40,0,MODE_EMA,PRICE_CLOSE,i);
 
   if (Val[i] > HighVal) HighVal = Val[i];
   }   
       
   if ((Val[1] / HighVal) < 0.86 )             {Print ("High = ", HighVal, "Std Dev = ",Val[1]); return (true);  } 
   else                                       {return (false); } 

}




______________________________________



Thanks Heaps Raptor! Works well now.








 
Sarkis:

Hi

Can somebody please help me with this consistent issue i have with executing a For loop inside a function. The same code in start() works ok but when its in a custom function i always get zero values for the variables.

The functions intention is to determine when the Bollinger bands contract by checking the current StdDev MA against the Highest Std Dev MA of 12 periods ago.

Your array has a size of zero elements  . . .

double Val[];

 . . .  that is how you have declared it.  Either give it a size or use ArrayResize()

 
Sarkis:

Thanks Heaps Raptor! Works well now.

 


You are welcome,  thank you for editing your post :-)
Reason: