Could you provide logs for this line?
Print("MA_handle =",MA_handle," error =",GetLastError());
Rosh :
It's very strange, try to update your terminal and recompile this sample.
I've just checked - all work properly.
It work out. Custom Moving Average ---------- Examples\\Custom Moving Average
It would be well if give a prompt "File not exist" in this case,
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
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);
}
//+------------------------------------------------------------------+