Download MetaTrader 5

Error in Adding Indicator as resources in EA(Compile as One).

To add comments, please log in or register
Suraj Neupane
200
Suraj Neupane  

I'm trying to add indicator as resources. Many indicators had added without any problem but some indicator shows following error.

cannot load '......\MQL4\Experts\SampleExpert.ex4::Indicators\SampleIndicator.ex4::Indicators\SampleIndicator.ex4'


 I'm assuming this is happends because "SampleIndicator" call itself as

iCustom(0,0,"SampleIndicator.ex4",........)

Is there any way to solve this error.  Thank You for your time. 

Jose Miguel Soriano
5036
Jose Miguel Soriano  
Suraj Neupane:

I'm trying to add indicator as resources. Many indicators had added without any problem but some indicator shows following error.

 I'm assuming this is happends because "SampleIndicator" call itself as

iCustom(0,0,"SampleIndicator.ex4",........)

Is there any way to solve this error.  Thank You for your time. 

#resource "\\Indicators\\TRIX.ex4"

 

void OnTick()

{

.../...

valueTRIX= iCustom(simb, timeFrame, "::Indicators\\TRIX.ex4", periodCalc, priceWork, nBuff, nBar);  

.../... 

Suraj Neupane
200
Suraj Neupane  
Jose Miguel Soriano:

#resource "\\Indicators\\TRIX.ex4"

 

void OnTick()

{

.../...

valueTRIX= iCustom(simb, timeFrame, "::Indicators\\TRIX.ex4", periodCalc, priceWork, nBuff, nBar);  

.../... 

Thank you very much for your time. I have already done that(didn't solve) but I also found the solution. This might helpful to anyone in future. 

Problem indeed was from indicator calling itself from indicator by this:

indicatorFileName = WindowExpertName(); 

which should be changed into following: 
indicatorFileName = GetRelativeProgramPath();
method GetRelativeProgramPath gives the same name as WindowExpertName() but it doesn't show error when adding indicator as EA's resource. Here is the GetRelativeProgramPath() METHOD's code:

///....

//+------------------------------------------------------------------+

//| GetRelativeProgramPath                                           |

//+------------------------------------------------------------------+

string GetRelativeProgramPath()

  {

   int pos2;

//--- get the absolute path to the application

   string path=MQLInfoString(MQL_PROGRAM_PATH);

//--- find the position of "\MQL4\" substring

   int    pos =StringFind(path,"\\MQL4\\");

//--- substring not found - error

   if(pos<0)

      return(NULL);

//--- skip "\MQL4" directory

   pos+=5;

//--- skip extra '\' symbols

   while(StringGetCharacter(path,pos+1)=='\\')

      pos++;

//--- if this is a resource, return the path relative to MQL5 directory

   if(StringFind(path,"::",pos)>=0)

      return(StringSubstr(path,pos));

//--- find a separator for the first MQL4 subdirectory (for example, MQL4\Indicators)

//--- if not found, return the path relative to MQL4 directory

   if((pos2=StringFind(path,"\\",pos+1))<0)

      return(StringSubstr(path,pos));

//--- return the path relative to the subdirectory (for example, MQL4\Indicators)

   return(StringSubstr(path,pos2+1));

  }

  

If it's helpful to anyone, you are welcome. 
Alain Verleyen
Moderator
33490
Alain Verleyen  
Suraj Neupane:

Thank you very much for your time. I have already done that(didn't solve) but I also found the solution. This might helpful to anyone in future. 

Problem indeed was from indicator calling itself from indicator by this:

indicatorFileName = WindowExpertName(); 

which should be changed into following: 
indicatorFileName = GetRelativeProgramPath();

As stated in the documentation.
To add comments, please log in or register