# Stochastic indicator return values

Hi

Apologies if a solution has been posted elsewhere, grateful if anyone could point me in the right direction. (Also

The problem encountered is that I'm trying to extract the values for an indicator, the stochastic oscillator in this instance. However the values returned are outside of the expected 0 to 100 range. The indicator when loaded on the chart however does seem to calculate the right values.

Pertinent bits of code below, however please let me know if I should post more.

1) The values for the Stochastic indicator are retrieved via CopyBuffer() per documentation. In this case, the handles are retrieved via iCustom() earlier

```        double array_0[];
ArraySetAsSeries(array_0, true);
CopyBuffer(indicator_list[2].indicator_handle, 0, 0, 3, array_0);
double Sto_Main = array_0[0];

double array_1[];
ArraySetAsSeries(array_1, true);
CopyBuffer(indicator_list[2].indicator_handle, 1, 0, 3, array_1);
double Sto_Sig = array_1[0];

Print("Indicator: ", indicator_list[2].indicator_name);
Print("Indicator handle: ", indicator_list[2].indicator_handle);
PrintFormat("Sto_Main: %d, Sto_Sig: %d", Sto_Main, Sto_Sig);

```

2020.04.20 19:02:42.555 2020.04.03 04:58:00   Indicator: Stochastic

2020.04.20 19:02:42.555 2020.04.03 04:58:00   Indicator handle: 12

2020.04.20 19:02:42.555 2020.04.03 04:58:00   Sto_Main: 311222032, Sto_Sig: -165991175

1a) The output values for the Main Line and Signal Line are some huge numbers above.

2) To double check if there wasn't any other issues/errors with referencing the right function, handle, etc, I also retrieved the values via iStochastic()

```        int new_handle = iStochastic(_Symbol, _Period, 5, 3, 3, MODE_SMA, STO_LOWHIGH);

ArrayFree(array_0);
ArraySetAsSeries(array_0, true);
CopyBuffer(new_handle, 0, 0, 3, array_0);
Sto_Main = array_0[0];

ArrayFree(array_1);
ArraySetAsSeries(array_1, true);
CopyBuffer(new_handle, 1, 0, 3, array_1);
Sto_Sig = array_1[0];

Print("New Indicator handle: ", new_handle);
PrintFormat("Sto_Main: %d, Sto_Sig: %d", Sto_Main, Sto_Sig);```

2a) Which gave this result - same big numbers but is indeed outputting a value.

2020.04.20 19:02:42.555 2020.04.03 04:58:00   New Indicator handle: 34

2020.04.20 19:02:42.555 2020.04.03 04:58:00   Sto_Main: 311222032, Sto_Sig: -165991100

3) On the chart, the values returned look normal:

Why are the return values not within the range of 0 to 100 for the Stochastic Oscillator?

PZ:

Example:

### An example of get values from the iStochastic indicator

• 2020.04.09
• www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...

Figured it out, looks like it was a formatting issue. As it turns out:

```Print("Sto_Main: ", Sto_Main);
Print("Sto_Sig: ", Sto_Sig);```

returns:

2020.04.20 22:13:08.506 2020.04.02 15:26:00   Sto_Main: 11.27450980392989

2020.04.20 22:13:08.506 2020.04.02 15:26:00   Sto_Sig: 18.47919483886281

whereas

```PrintFormat("Sto_Main: %d", Sto_Main);
PrintFormat("Sto_Sig: %d", Sto_Sig);```

returns:

2020.04.20 22:13:08.506 2020.04.02 15:26:00   Sto_Main: -1936941349

2020.04.20 22:13:08.506 2020.04.02 15:26:00   Sto_Sig: -2091822104

I have no idea why. I thought %d flag gives a double format (but is actually 'signed decimal integer'?). At the same time, I thought %e should give a double format too, but that results in a large number too. Both %d and %e formats to a value that is much larger than the actual value.

If there are experts who could enlighten me as to why, very much appreciated.

PZ :

Figured it out, looks like it was a formatting issue. As it turns out:

returns:

2020.04.20 22:13:08.506 2020.04.02 15:26:00   Sto_Main: 11.27450980392989

2020.04.20 22:13:08.506 2020.04.02 15:26:00   Sto_Sig: 18.47919483886281

whereas

returns:

2020.04.20 22:13:08.506 2020.04.02 15:26:00   Sto_Main: -1936941349

2020.04.20 22:13:08.506 2020.04.02 15:26:00   Sto_Sig: -2091822104

I have no idea why. I thought %d flag gives a double format (but is actually 'signed decimal integer'?). At the same time, I thought %e should give a double format too, but that results in a large number too. Both %d and %e formats to a value that is much larger than the actual value.

If there are experts who could enlighten me as to why, very much appreciated.

Use a simple form:

`DoubleToString(`
Reason: