The question has been dogging me for a while, are there any advantages/disadvantages one over another?
I'd just as soon use _Symbol and _Period, are there any downsides?
Using _Symbol and _Period is a perfectly fine and there are no major downside.
However, if you need more flexibility or want to avoid potential issues with global variables, using Symbol() and Period() can be a good alternative.
Using _Symbol and _Period is a perfectly fine and there are no major downside.
However, if you need more flexibility or want to avoid potential issues with global variables, using Symbol() and Period() can be a good alternative.
Meaning when running indicators on other charts? Or are there other cases that require more flexibility as well?
https://www.mql5.com/en/docs/check/symbol
Symbol
string Symbol();
Return Value:
Value of the _Symbol system variable, which stores the name of the current chart symbol.
Symbol() returns _Symbol.
That is, it is one and the same. 2 ways to obtain the same value.
Meaning when running indicators on other charts? Or are there other cases that require more flexibility as well?
The main case where using Symbol() and Period() provides more flexibility - is when running indicators on other charts.
Beyond that, Symbol() and Period() can also be useful when developing more reusable functions or strategies that need to work across multiple symbols and timeframes.
Symbol() returns _Symbol.
That is, it is one and the same. 2 ways to obtain the same value.
Likewise for Period() and _Period.
https://www.mql5.com/en/docs/check/period
Period
ENUM_TIMEFRAMES Period();
Return Value
The contents of the _Period variable that contains the value of the current chart timeframe. The value can be one of the values of the ENUM_TIMEFRAMES enumeration.
PERIOD_CURRENT is one of the identifiers in the ENUM_TIMEFRAMES enumeration.
- ENUM_TIMEFRAMES:
https://www.mql5.com/en/docs/constants/chartconstants/enum_timeframes - enum:
https://www.mql5.com/en/docs/basis/types/integer/enumeration
ENUM_TIMEFRAMES is the data type of _Period and the return type of Period(). Once again I draw your attention to this:
https://www.mql5.com/en/docs/check/period
The value can be one of the values of the ENUM_TIMEFRAMES enumeration.
You can read about what NULL is here:
https://www.mql5.com/en/docs/basis/types/void
NULL itself has no relation to the symbol. But in some functions (for which it is explicitly stated in the documentation) NULL can be used as a way to indicate that the current symbol should be used
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
The question has been dogging me for a while, are there any advantages/disadvantages one over another?
I'd just as soon use _Symbol and _Period, are there any downsides?