It returns -1 because the data hasn't been loaded yet. To prevent this from happening use BarsCalculated().
int handle; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping handle=iCCI(_Symbol,PERIOD_D1,14,PRICE_TYPICAL); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- if(BarsCalculated(handle)<10) return(0); //--- double Buffer[]; printf("Total copied = %d",CopyBuffer(handle,0,0,10,Buffer)); //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Ernst Van Der Merwe:
It returns -1 because the data hasn't been loaded yet. To prevent this from happening use BarsCalculated().
How great you are.
Very good suggestion.
Thanks so much.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
This is MQL5 language questions.
I guess this have been asked so many times by different coders.
But I try once more if MQL5.com can fix this in the near future.
The concept of handle and CopyBuffer works if you want to copy the indicator array for the same time frame as your chart.
However, if you are trying to copy indicator array for different time frame to your chart, then it fails.
For example, if you want to copy indicator array for Daily time frame and if your chart is Hourly time frame, then CopyBuffer always fails. It works if you copy indicator buffer of hourly and you are using hourly chart.
Could we please fix this errors ? or any work around solution ?
Hopefully I don't have to post the same questions over and over again.