CopyBuffer return -1

samjesse

Active Trader
Aug 30, 2011
118
0
27
Hi

I have 1M chart among 3 more charts on the screen, A customer indicator is attached on both charts.
The following does NOT produce INVALID_HANDLE
Why is the CopyBuffer returning -1 ?
MQL5:
if(handleStock==INVALID_HANDLE) Print ("invalid stochastic handle.");
int copied = CopyBuffer(handleStock,0,0,bars,stochBuffer);

When I run the code initially, it works fine and does not return -1, but when onCalculate works, it gives that error.

the Docs:
if requested timeseries are not yet built or they need to be downloaded from the server,
that can not apply here since the chart is on the screen. right?

many thx
 
Last edited by a moderator:

samjesse

Active Trader
Aug 30, 2011
118
0
27
I feel I should include more of the code

MQL5:
/////////////// INDICATOR FILE
#include <file1.mqh>
#property indicator_buffers 8
// code...

MQL5:
////////////FILE1.mqh
#include <File2.mqh>
//code...
class ABC
{
private:
double stochBuffer[300];
int handleStock;
double low[300];
//code...
public:
int bars;
void func1(void);
}
// constructor
ABC(string name, ENUM_TIMEFRAMES _prd)
{
_symbol = name;
_period = _prd;
bars = ArraySize(low);
}
 
void ABC::func1(void)
{
if(handleStock==INVALID_HANDLE) Print ("invalid stochastic handle.");
int copied = CopyBuffer(handleStock,0,0,bars,stochBuffer);
}
 
Last edited by a moderator: