Download MetaTrader 5
To add comments, please log in or register
Do you know that MQL5 has structures?
Point Zero
848
Point Zero 2016.05.06 21:35 

Dear everyone!

I hope you are fine. I am writing an indicator that uses another one as resource, called "foobar.ex4". The calling indicator is named "FooBarScanner.ex4".

#resource "\\Indicators\\FooBar.ex4" 

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[])
{
    double value = iCustom(Symbol(), Period(), "::Indicators\\FooBar.ex4", 1, 1);
}



This particular indicator (FooBar.ex4) is recursive, meaning that inside its own code, it calls itself a few times to get information with other settings.

double recursive_value = iCustom(Symbol(), Period(), WindowExpertName(), 0, 1);


The FooBar.ex4 indicator works as intended, gets information from itself using recursive calls and draws on the chart without freezing. This is not an infinite loop problem.

However, when I execute the indicator which uses FooBar.ex4 as a resource, I get several errors in the mt4 terminal, like this one:

2016.05.06 17:34:14.031 cannot load 'C:\Program Files (x86)\MetaTrader - AxiTrader\MQL4\indicators\FooBarScanner.ex4::Indicators\FooBar.ex4::Indicators\FooBar.ex4'


It seems that the WindowExpertName() function returns a very different thing when an indicator is used as a resource and the recursive call fails.

How should I do the iCustom() call inside FooBar.mq4 for the indicator to work as intended, and the iCustom() call tok work properly as well? Any ideas?

Thanks in advance!

Alain Verleyen
Moderator
28563
Alain Verleyen 2016.05.06 23:00  

Maybe you could try to read the documentation ?

The path to itself can be received using GetRelativeProgramPath() function.

Point Zero
848
Point Zero 2016.05.06 23:40  
angevoyageur:

Maybe you could try to read the documentation ?


Thanks Angevoyageur, helpful as always. 

whroeder1
13613
whroeder1 2016.05.07 14:00  
angevoyageur: Maybe you could try to read the documentation ?
The path to itself can be received using GetRelativeProgramPath() function.
Except that no such function listed List of MQL4 Functions - MQL4 Reference
Fernando Carreiro
1465
Fernando Carreiro 2016.05.07 15:08  
WHRoeder:
angevoyageur: Maybe you could try to read the documentation ?
The path to itself can be received using GetRelativeProgramPath() function.
Except that no such function listed List of MQL4 Functions - MQL4 Reference

It is not a built-in function! It is part of the coding example in the Resources documentation (Working with custom indicators included as resources): https://docs.mql4.com/runtime/resources

//+------------------------------------------------------------------+
//| 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));
  }
Alain Verleyen
Moderator
28563
Alain Verleyen 2016.05.07 15:59  
WHRoeder:
angevoyageur: Maybe you could try to read the documentation ?
The path to itself can be received using GetRelativeProgramPath() function.
Except that no such function listed List of MQL4 Functions - MQL4 Reference
Sorry I forgot the link, it was late. FMIC gave it.
/
To add comments, please log in or register