When I calc other timeframe indicator with CopyBuffer function, there is always error 4806.
below is the example code, Can anybody help, thanks.
always happens error code 2 #4806
and handle is fine, I already checked with
if (nHandle_2 == INVALID_HANDLE) {printf("handle error 2");}
Use BarsCalculated() to check if data has been loaded. Also keep in mind that PERIOD_D1 has a different rates_total count than the chart timeframe.
if (CopyBuffer(nHandle_1,0,0,rates_total - ExtPeriodRSI - 1,ExtRSI_1)<0) printf("error code 1 #" + GetLastError()); int ratesTotal=Bars(_Symbol,PERIOD_D1); if(BarsCalculated(nHandle_2)<ratesTotal) return(0); if (CopyBuffer(nHandle_2,0,0,ratesTotal - ExtPeriodRSI - 1,ExtRSI_2)<0) printf("error code 2 #" + GetLastError()); return(rates_total);
Use BarsCalculated() to check if data has been loaded. Also keep in mind that PERIOD_D1 has a different rates_total count than the chart timeframe.
changed codes like this
int ratesTotal=Bars(_Symbol,PERIOD_D1); if (CopyBuffer(nHandle_1,0,0,rates_total - ExtPeriodRSI - 1,ExtRSI_1)<0) printf("error code 1 #" + GetLastError()); if (CopyBuffer(nHandle_2,0,0,ratesTotal - ExtPeriodRSI - 1,ExtRSI_2)<0) printf("error code 2 #" + GetLastError()); if(BarsCalculated(nHandle_2)<ratesTotal) printf("calculated bars " + BarsCalculated(nHandle_2) + " ratestotal " + ratesTotal);
and message shows
calculated bars -1 ratestotal 2487
data has not been loaded , what should I do?
thanks.
changed codes like this
and message shows
calculated bars -1 ratestotal 2487
data has not been loaded , what should I do?
thanks.
If data hasn't been loaded, return(0); and wait for the next tick.
if (CopyBuffer(nHandle_1,0,0,rates_total - ExtPeriodRSI - 1,ExtRSI_1)<0) printf("error code 1 #" + GetLastError()); int ratesTotal=Bars(_Symbol,PERIOD_D1); if(BarsCalculated(nHandle_2)<ratesTotal) return(0); if (CopyBuffer(nHandle_2,0,0,ratesTotal - ExtPeriodRSI - 1,ExtRSI_2)<0) printf("error code 2 #" + GetLastError()); printf("calculated bars %d ratestotal %d",BarsCalculated(nHandle_2),ratesTotal); return(rates_total);
If data hasn't been loaded, return(0); and wait for the next tick.
thanks , problem solved.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
When I calc other timeframe indicator with CopyBuffer function, there is always error 4806.
below is the example code, Can anybody help, thanks.
always happens error code 2 #4806