Naming a variable

 

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,

 

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?‌

 
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.

 

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
 
Thank you all for your helpful comments.
 

It's indeed useless BUT possible - example:

#define x(y,z) {int var_##y=z;}
switch(Period())
  {
   case PERIOD_M1 : x(M1,100); break;
   case PERIOD_M5 : x(M5,500); break;
   //--- etc.
  }
 
Marcin Madrzak:

It's indeed useless BUT possible - example:

I don't think it was possible at the time the question was asked.
Reason: