Download MetaTrader 5
To add comments, please log in or register
Do you wonder how to use widgets? Read the article!
Suraj Neupane
174
Suraj Neupane 2016.04.24 12:51 

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
4941
Jose Miguel Soriano 2016.04.25 00:11  
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
174
Suraj Neupane 2016.04.25 14:07  
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
30299
Alain Verleyen 2016.04.25 16:53  
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