Download MetaTrader 5

Naming a variable

To add comments, please log in or register
parham.trader
375
parham.trader  

Dear firends,

I want to assign a name on a variable and I want the name to include the Timeframe or the symbol name of the current chart. As an example suppose that I'm running my indicator on "W1" timeframe so I want my variable name to be XYZ_W1 . I want to know is it possible in MQL4 to do so ? Or as another example, suppose that I've attached my indicator on EURUSD chart and I'm going to assign ABC_EURUSD as the name of a variable, would it be possible to do so ?

t‌hanking in advance for your kind guidance,

whroeder1
16572
whroeder1  

You are writing code, there is no chart, there is no timeframe. The code must be done before you can put it on a chart. So no, not possible.

Even if it were, what are you going to do if you put it on another pair/tf? Are you going to rename all your variables? Why?‌

Alain Verleyen
Moderator
33807
Alain Verleyen  
parham.trader:

Dear firends,

I want to assign a name on a variable and I want the name to include the Timeframe or the symbol name of the current chart. As an example suppose that I'm running my indicator on "W1" timeframe so I want my variable name to be XYZ_W1 . I want to know is it possible in MQL4 to do so ? Or as another example, suppose that I've attached my indicator on EURUSD chart and I'm going to assign ABC_EURUSD as the name of a variable, would it be possible to do so ?

t‌hanking in advance for your kind guidance,

As stated by WHRoeder, not possible and completely useless. And a very bad practice if it was possible.

Frederic Metraux
514
Frederic Metraux  

This is possible with global variables: https://docs.mql4.com/globals/globalvariableset

GlobalVariableSet - Global Variables of the Terminal - MQL4 Reference
GlobalVariableSet - Global Variables of the Terminal - MQL4 Reference
  • docs.mql4.com
GlobalVariableSet - Global Variables of the Terminal - MQL4 Reference
parham.trader
375
parham.trader  
Thank you all for your helpful comments.
To add comments, please log in or register