Difference between Symbol() and _Symbol

 
What is difference between Symbol() and _Symbol? Any help would be highly appreciated. 
 
First is a function call, second is a predefined variable. Both give the same extract string.
 
William Roeder:
First is a function call, second is a predefined variable. Both give the same extract string.
dear @William Roeder

In general, which one is faster?

Does their execution time difference?
 

Forum on trading, automated trading systems and testing trading strategies

What is different between Symbol() and _Symbol

fxsaber, 2019.07.07 14:47

void Func( const string& ) {}

void OnStart()
{
  Func(Symbol()); // ERROR: 'Symbol' - parameter passed as reference, variable expected
  Func(_Symbol);  // OK   
}
 
Koros Jafarzadeh:
dear @William Roeder

In general, which one is faster?

Does their execution time difference?

Faster is to use _Symbol because it is a definition.


Symbol() is a function, so it has to be executed to retrieve the symbol name every time it is called. 


Your code is returning error because your Func() definition expects a CONST string. So it only accepts Static parameters. And you cannot pass a function return to it.

Either modify it removing CONST so you can pass Symbol() to it as a parameter. Or use _Symbol which is faster and ALSO IS a Static Variable ;)

 
rrocchi:

Faster is to use _Symbol because it is a definition.


Symbol() is a function, so it has to be executed to retrieve the symbol name every time it is called. 


Your code is returning error because your Func() definition expects a CONST string. So it only accepts Static parameters. And you cannot pass a function return to it.

Either modify it removing CONST so you can pass Symbol() to it as a parameter. Or use _Symbol which is faster and ALSO IS a Static Variable ;)

thanks @rrocchi, very good explanation
 
rrocchi:

Faster is to use _Symbol because it is a definition.

Symbol() is a function, so it has to be executed to retrieve the symbol name every time it is called.

Actually I think there's no difference in speed, it gets sort of optimized during compilation.

 
Comments that do not relate to this topic, have been moved to "Off-topic posts".
Reason: