Download MetaTrader 5

SymbolInfoString => SYMBOL_PATH returns nothing

To add comments, please log in or register
David Saulnier
405
David Saulnier  
Alert(SymbolInfoString("EURUSD", SYMBOL_PATH));

I expected this return "MajorFX" folder but it returns a blank string.

Same for all symbols.

Simon Gniadkowski
Moderator
18042
Simon Gniadkowski  
DavidS777:

I expected this return "MajorFX" folder but it returns a blank string.

Same for all symbols.

Are you certain of your symbol name ? "EURUSD" ? not "EURUSD." or "EURUSDm" ? or some other extended EURUSD . . . try using Symbol() on a "EURUSD" chart to make certain. Other than that you might want to post some complete test code and contact the Service Desk <---- follow instructions in the post in this link
David Saulnier
405
David Saulnier  
   string s;
   if(SymbolInfoString(Symbol(), SYMBOL_PATH, s))
   {
      Alert(Symbol()+" => "+s);
   }
   else
   {
      int lastErr = GetLastError();
      Alert("[ERROR] #"+lastErr+": "+ErrorDescription(lastErr));
  }


I got: [ERROR] #4051: invalid function parameter value

Don't see where I'm wrong ?

Simon Gniadkowski
Moderator
18042
Simon Gniadkowski  
DavidS777:

I got: [ERROR] #4051: invalid function parameter value

Don't see where I'm wrong ?

Where is the error coming from ? do you ResetLastError() before calling SymbolInfoString() ?

RaptorUK:
. . . . you might want to post some complete test code and contact the Service Desk <---- follow instructions in the post in this link
fx1cloud9
304
fx1cloud9  
DavidS777:

I got: [ERROR] #4051: invalid function parameter value

Don't see where I'm wrong ?


Then try to import it explicitly in your code, at the top:

#import "user32.dll"
string ErrorDescription(int error_code);
#import

David Saulnier
405
David Saulnier  
RaptorUK:
Where is the error coming from ? do you ResetLastError() before calling SymbolInfoString() ?



Yes, I've added ResetLastError() before calling SymbolInfoString() and same issue (4051).

I'm sending to Service Desk the COMPLETE source code which is very small :

#include <stdlib.mqh>

//------------------------------------------------------------------------------------------------------------------------------
void OnTick()
//------------------------------------------------------------------------------------------------------------------------------
{
   string s;
   ResetLastError();
   if(SymbolInfoString(Symbol(), SYMBOL_PATH, s))
      Alert(Symbol()+" => "+s);
   else
   {
      int lastErr = GetLastError();
      Alert("[ERROR] #"+lastErr+": "+ErrorDescription(lastErr));
  }
  
}

@Fx18 : thanks for import suggestion but this is not necessary.

Thanks
fx1cloud9
304
fx1cloud9  
DavidS777:

I've added ResetLastError() and same issue.

@Fx18 : thanks for import suggestion but this is not necessary.

I'm sending to Service Desk the COMPLETE source code which is very small.

Thanks


Yes, this is just a workaround to test this.

If there is no compiler error after having imported the function declaration, then this means there is sure a problem that should be reported to Service Desk.

Keith Watford
Moderator
10566
Keith Watford  

This sort of stuff is way above my comprehension level, but because I like to learn I looked up this function in the reference.

I have no idea what "Path in the symbol tree" means
#include <stdlib.mqh>

//------------------------------------------------------------------------------------------------------------------------------
void OnTick()
//------------------------------------------------------------------------------------------------------------------------------
{
   string s;
   ResetLastError();
   if(SymbolInfoString(Symbol(), SYMBOL_PATH, s))
      Alert(Symbol()+" => "+s);
   else
   {
      int lastErr = GetLastError();
      Alert("[ERROR] #"+lastErr+": "+ErrorDescription(lastErr));
  }
  
}

but I would think that the last parameter needs a value for the function to work properly.

string s is declared, but not initialised, does it not need a value for this function?

Sorry if I am just being ignorant.

Simon Gniadkowski
Moderator
18042
Simon Gniadkowski  
GumRai:

This sort of stuff is way above my comprehension level, but because I like to learn I looked up this function in the reference.

I have no idea what "Path in the symbol tree" means

but I would think that the last parameter needs a value for the function to work properly.

string s is declared, but not initialised, does it not need a value for this function?

Sorry if I am just being ignorant.

string s is passed by reference, the function saves the returned value to this string

There are two ways of using SymbolInfoString() . . . .

SymbolInfoString

Returns the corresponding property of a specified symbol. There are 2 variants of the function.

1. Immediately returns the property value.

string SymbolInfoString(
string name, // Symbol
ENUM_SYMBOL_INFO_STRING prop_id // Property identifier
);

2. Returns true or false, depending on the success of a function. If successful, the value of the property is placed in a placeholder variable passed by reference in the last parameter.

bool SymbolInfoString(
string name, // Symbol
ENUM_SYMBOL_INFO_STRING prop_id, // Property identifier
string& string_var // Here we assume the property value
);


David Saulnier
405
David Saulnier  

In 2nd case, the string passed is just a placeholder to retrieve the value (a pointer like in C++), so it's initialization is not necessary (I guess). It just mean "we want the value in this target variable".

However with case 1 it is not working too (returned string is empty). I'm waiting info from Service Desk.

Much thanks for your help in this stuff.

Alain Verleyen
Moderator
33614
Alain Verleyen  
GumRai:

This sort of stuff is way above my comprehension level, but because I like to learn I looked up this function in the reference.

I have no idea what "Path in the symbol tree" means

but I would think that the last parameter needs a value for the function to work properly.

string s is declared, but not initialised, does it not need a value for this function?

Sorry if I am just being ignorant.


It returns the path of the symbol in Symbols window, for example : EURUSD => Forex\MajorFX\EURUSD

12
To add comments, please log in or register