Setting a Variable Whose Name is Contained Within a Separate Variable

To add comments, please log in or register
Neils
49
Neils  

Hi

I have an Array which contains names of variables. Is there a way to use the Array entries to assign a value instead of having to do...


                     if (Per_Array[i,0]) = "Ind0_DonchianPeriodsEntry"

                        Ind0_DonchianPeriodsEntry=GVResult

                     else

                     if (Per_Array[i,0]) = "Ind0_DonchianPeriodsExit"

                        Ind0_DonchianPeriodsExit=GVResult

                     else 

etc


Any help would be appreciated 



Anthony Garot
1813
Anthony Garot  
Neils:

Hi

I have an Array which contains names of variables. Is there a way to use the Array entries to assign a value instead of having to do...


There is, to my knowledge, no eval() functionality in MQL4/MQL5.

For your specific task, perhaps a hash would work for you.

https://www.mql5.com/en/forum/220383

Libraries: CDictionary class
Libraries: CDictionary class
  • 2017.11.20
  • www.mql5.com
CDictionary class: Author: Enrico Lambino...
Neils
49
Neils  
Anthony Garot:


There is, to my knowledge, no eval() functionality in MQL4/MQL5.

For your specific task, perhaps a hash would work for you.

https://www.mql5.com/en/forum/220383

Hi Anthony,


Thank you for sharing your idea. Apologies,I really should have mentioned that I'm using MQL4 - Your suggestion looks to be MQL5 maybe.

Fernando Carreiro
4145
Fernando Carreiro  
Neils: Hi Anthony, Thank you for sharing your idea. Apologies,I really should have mentioned that I'm using MQL4 - Your suggestion looks to be MQL5 maybe.
Classes (OOP) works in both MQL4 and MQL5!
nicholi shen
1841
nicholi shen  
Neils:

Hi Anthony,


Thank you for sharing your idea. Apologies,I really should have mentioned that I'm using MQL4 - Your suggestion looks to be MQL5 maybe.

It should work in either platform, however, using mutable strings to specify state is a dangerous practice. I can't help but to think there is likely a better, simpler, and safer way to accomplish what you are ultimately trying to achieve. 

To add comments, please log in or register