Getting garbage values from iStochastic function

 

Here is the code and the output of the Strategy Tester:  

void OnInit()
{
double K[],D[];

int s  = iStochastic(_Symbol,PERIOD_M1,5,3,3,MODE_SMA,STO_LOWHIGH);
ArraySetAsSeries(K,true);
CopyBuffer(s,0,0,15,K);
 for (int i=0; i< ArraySize(K); i++)
 {PrintFormat("K%d:  %f",i,K[i]);}


}

The output is here:

2018.03.23 17:52:23.771 EURUSD,M1: testing of Experts\testing lines and trdae.ex5 from 2018.02.01 00:00 to 2018.02.20 00:00 started
2018.03.23 17:52:23.821 2018.02.01 00:00:00   K0:  0.000000
2018.03.23 17:52:23.821 2018.02.01 00:00:00   K1:  0.000000
2018.03.23 17:52:23.821 2018.02.01 00:00:00   K2:  0.000000
2018.03.23 17:52:23.821 2018.02.01 00:00:00   K3:  0.000000
2018.03.23 17:52:23.821 2018.02.01 00:00:00   K4:  0.000000
2018.03.23 17:52:23.821 2018.02.01 00:00:00   K5:  0.000000
2018.03.23 17:52:23.821 2018.02.01 00:00:00   K6:  0.000000
2018.03.23 17:52:23.821 2018.02.01 00:00:00   K7:  0.000000
2018.03.23 17:52:23.821 2018.02.01 00:00:00   K8:  0.000000
2018.03.23 17:52:23.821 2018.02.01 00:00:00   K9:  0.000000
2018.03.23 17:52:23.821 2018.02.01 00:00:00   K10:  -199836181689466826799237394770318879446132938967474237529901448300177121542331695157382317059237724271211152856484244886720180840440527383821209628107006660663428982847878694191497216.000000
2018.03.23 17:52:23.821 2018.02.01 00:00:00   K11:  0.000000
2018.03.23 17:52:23.821 2018.02.01 00:00:00   K12:  0.000000
2018.03.23 17:52:23.821 2018.02.01 00:00:00   K13:  0.000000
2018.03.23 17:52:23.821 2018.02.01 00:00:00   K14:  0.000000

I am confused. As previously I was getting correct values but now the values are all garbage. Kindly, help me.

 

That's what is happening when nothing is checked.

  • Is your handle valid ?
  • Is CopyBuffer() returning an error ? How much data were copied ?

The handle is (iStochastic in OnInit), the CopyBuffer in OnTick (or OnTimer).

Please read the documentation !

 
Alain Verleyen:

That's what is happening when nothing is checked.

  • Is your handle valid ?
  • Is CopyBuffer() returning an error ? How much data were copied ?

The handle is (iStochastic in OnInit), the CopyBuffer in OnTick (or OnTimer).

Please read the documentation !

Is there no way to get the values at OnInit()?

Reason: