Global Variables of the Terminal expiry - page 2

 
Fernando Carreiro #:

Just assign the "input" to a globally scoped variable during OnInit(), and then you can use and modify that variable as much as you wish.

thanks, yes I do this for my my EAs already.. it results in many, many lines of extra code though over MQL4 (I have a lot of inputs) but I guess that is the price I must pay to make it compatible with MQL5 as well.

Personally I would rather just code for MQL5 but then this really limits which brokers can be used.

 
ycomp #:thanks, yes I do this for my my EAs already.. it results in many, many lines of extra code though over MQL4 (I have a lot of inputs) but I guess that is the price I must pay to make it compatible with MQL5 as well. Personally I would rather just code for MQL5 but then this really limits which brokers can be used.

The MQL4 way of modifying the user inputs is not the best practice. They are user inputs and should no be changed.

The MQL5 way is more correct in my opinion and forces you to rethink things in a more structured way.

If it is causing you to write many extra lines of code, then your approach is not very structured and needs to be revised.

 
ycomp #:

well it would have been nice to use global variables because then I wouldn't have to deal with potential errors from trying to read files instead of using global variables. 

I need to keep track of an important number that is persistent. Well a bunch of them but only one of these per EA. 

I understand about checking to keep them alive, however this only works if you check once in 4 weeks. Which will happen much of the time but cannot be guaranteed.

Service program is a good idea but not really that applicable for my situation, because I might switch accounts and come back to an older account later (after more than 4 weeks) (ok I guess that doesn't matter but I mean the a terminal might not be running for more than a month in some cases)

So I guess I will need to store it in files and then deal with error handling for that. It is a crucial number for managing of my trading operations with the EA.

honestly if I was coding just MQL4 I would just use extern inputs, but for some reason that got removed in MQL5.
Use Global Variable that backup to files. Use a function to access the global and if the global isnt present to access the file. You can write custom functions that operate like globals that do the background work.
Reason: