I wanted 3 MA lines in different colors, so I wrote an indicator with three MAs. If I drop it on a chart it works perfectly, but I just can't seem to call it from the EA. The error message in the log is:
2025.06.15 01:03:22.316 2025.06.09 02:14:39 cannot open file 'F:\FOREX_DEMO\MQL4\indicators\MAs_Ind.ex4' [2]
I can't find an explaination for the [2]
Here's the call:
double MA_Lines = iCustom(NULL,0,"MAs_Ind",FastMA_Periods,2,0,MidlMA_Periods,2,0,SlowMA_Periods,2,0,1,0,0);
Here's the code:
#property description "MAs_Ind"
#property indicator_chart_window
#property strict
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Red
#property indicator_color3 Blue
double Buffer1[];
double Buffer2[];
double Buffer3[];
extern int MA1_Periods = 5; // number of periods used in calc of the MA line, 0=don't show this line
extern int MA1_Method = 2; // 0=Simple Moving Average, 1=Exponential Moving Average, 2=Smoothed Moving Average, 3=Linear Weighted Moving Average
extern int MA1_Price = 0; // 0=close, 1=open, 2=high, 3=low, 4=median(h+l/2), 5=typical(h+l+c/3),6=weighted close(h+l+c+c/4) used for slope calc
extern int MA2_Periods = 15; // the number of periods to use in calculating a moving average line as a Stop Loss, 0=don't show this line
extern int MA2_Method = 2; // 0=Simple Moving Average, 1=Exponential Moving Average, 2=Smoothed Moving Average, 3=Linear Weighted Moving Average
extern int MA2_Price = 0; // 0=close, 1=open, 2=high, 3=low, 4=median(h+l/2), 5=typical(h+l+c/3),6=weighted close(h+l+c+c/4) used for slope calc
extern int MA3_Periods = 50; // the number of periods to use in calculating a moving average line to determine whether to take positions, 0=don't show this line
extern int MA3_Method = 0; // 0=Simple Moving Average, 1=Exponential Moving Average, 2=Smoothed Moving Average, 3=Linear Weighted Moving Average
extern int MA3_Price = 0; // 0=close, 1=open, 2=high, 3=low, 4=median(h+l/2), 5=typical(h+l+c/3),6=weighted close(h+l+c+c/4) used for slope calc
extern int Line_Width = 1; // width of indicator lines
int OnInit()
{
IndicatorShortName("MAs");
SetIndexStyle(0,DRAW_LINE,EMPTY,Line_Width);
SetIndexBuffer(0,Buffer1);
SetIndexLabel(0,"MA"+IntegerToString(MA1_Periods));
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_LINE,EMPTY,Line_Width);
SetIndexBuffer(1,Buffer2);
SetIndexLabel(1,"MA"+IntegerToString(MA2_Periods));
SetIndexEmptyValue(1,0.0);
SetIndexStyle(2,DRAW_LINE,EMPTY,Line_Width);
SetIndexBuffer(2,Buffer3);
SetIndexLabel(2,"MA"+IntegerToString(MA3_Periods));
SetIndexEmptyValue(1,0.0);
for(int i=1; i<=ObjectsTotal(); i++) if ( StringSubstr(ObjectName(i),0,7) == "MAs_Ind" ) ObjectDelete(ObjectName);
return(0);
}
int deinit()
{
return(0);
}
int OnCalculate(const int rates_total, // size of input time series
const int prev_calculated, // bars handled in previous call
const datetime& time[], // Time
const double& open[], // Open
const double& high[], // High
const double& low[], // Low
const double& close[], // Close
const long& tick_volume[], // Tick Volume
const long& volume[], // Real Volume
const int& spread[] // Spread
)
{
int limit=rates_total-prev_calculated;
for(int i=0; i<limit; i++)
{
Buffer1[i]=iMA(NULL,0,MA1_Periods,0,MA1_Method,MA1_Price,i);
if (MA2_Periods > 0 ) Buffer2[i]=iMA(NULL,0,MA2_Periods,0,MA2_Method,MA2_Price,i);
if (MA3_Periods > 0 ) Buffer3[i]=iMA(NULL,0,MA3_Periods,0,MA3_Method,MA3_Price,i);
}
return(0);
}
#include <WinUser32.mqh>
// end of text
Any help is greatly appreciated; when I drag it from the indicators list on the left, I have to put in the 10 parameters that the it should pickup from the call. Of course, if you use any of the indicator code it's at your own risk; I take no responsibility for the code's accuracy or functionality.
Your error-message reads :
"(...)
2025.06.15 01:03:22.316 2025.06.09 02:14:39 cannot open file 'F:\FOREX_DEMO\MQL4\indicators\MAs_Ind.ex4' [2]"
However, the standard MQL4 installation demands this :
"Custom indicators are stored in
<_terminal_directory_>\MQL4\Indicators
"
Use proper case ( typing Indicators
instead of indicators
) and the compilation ought find the file, where it ought be, and continues its work.