NULL, _Symbol, Symbol(), 0, _Period, CURRENT_PERIOD, Period(): Does it matter?

 

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?

 
Millard Melnyk:

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.

 
MQL4 or MQL5?
 
Oleksandr Medviediev #:

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?

 
Vladislav Boyko #:
MQL4 or MQL5?

MQL5. I was once told by a very sharp coder (years ago, can't remember his name) that he wouldn't answer my questions until I'd switched to the "new terminal", so I did. Still getting reoriented from my MQL4 past...

 

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.

 
Millard Melnyk #:

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.

 
Vladislav Boyko #:

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.

 
Vladislav Boyko #: MQL4 or MQL5?

Either. MQL4 has had those predefined variables for years now.

 

PERIOD_CURRENT is one of the identifiers in the ENUM_TIMEFRAMES 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

Reason: