Trying to get iMA of a Symbol

 

Hi

I am new to MQL5, and I was trying a small script code (below) and I have one question.
Why the CopuBuffer is giving me -1 and error is giving me 4806 ?

void OnStart() {

   double ma[];
   ArraySetAsSeries(ma,true);
   string sym="#ABT";
   SymbolSelect(sym,true);
   int handle= iMA(sym,PERIOD_D1,200,0,MODE_SMA,PRICE_CLOSE);
   Comment("Handle: "+(string)handle);
   
   if (CopyBuffer(handle,0,0,3,ma)== -1){
      int error=GetLastError();
      Comment("Error: "+(string)error);
      ResetLastError();
   }else{
      Comment(ma[0]);
   }
   
   SymbolSelect(sym,false);
}
 

Perhaps you should read the manual, especially the examples. They all (including iCustom) return a handle (an int.) You get that in OnInit. In OnTick (after the indicator has updated its buffers,) you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08
          How to call indicators in MQL5 - MQL5 Articles 12 March 2010

Reason: