Why the iCustom function dosn't work?

 

even in the sample code in help file,"copy" always <=0. How about anyone else?

 

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//---- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  Red
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int MA_Period=21;
input int MA_Shift=0;
input ENUM_MA_METHOD MA_Method=MODE_SMA;
//--- indicator buffers
double         Label1Buffer[];
//--- Handle of the Custom Moving Average.mq5 user indicator
int MA_handle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
   ResetLastError();
   MA_handle=iCustom(NULL,0,"Custom Moving Average",
                     MA_Period,
                     MA_Shift,
                     MA_Method,
                     PRICE_CLOSE // using the close prices
                     );
   Print("MA_handle =",MA_handle,"  error =",GetLastError());
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//--- Copy the values of the indicator CHO our indicator buffer
   int copy=CopyBuffer(MA_handle,0,0,rates_total,Label1Buffer);
   Print("copy =",copy,"    rates_total =",rates_total);
//--- If our attempt has failed - Report this
   if(copy<=0)
      Print("An attempt to get the values if Custom Moving Average has failed");
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Language Basics / Preprocessor / Program Properties (#property) - Documentation on MQL5
 

Could you provide logs for this line?

   Print("MA_handle =",MA_handle,"  error =",GetLastError());



 
Rosh  :

Could you provide logs for this line?



2009.12.23 22:22:02 iCustom (GBPUSD,H1) MA_handle = -1   error = 4807

 
bcsunwww   :


2009.12.23 22:22:02 iCustom (GBPUSD,H1) MA_handle = -1   error = 4807

It's very strange, try to update your terminal and recompile this sample.

I've just checked - all work properly.

 
Rosh  :

It's very strange, try to update your terminal and recompile this sample.

I've just checked - all work properly.



Thanks for your reply ,I'll try it again.
 

It work out.                          Custom Moving Average   ----------          Examples\\Custom Moving Average

 

It would be well if give a  prompt "File not exist" in this case,

Reason: