![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
No.
First tick does not change it. It is a variable of the 'extern' sort that will be changed manually on the chart.
Then remove that extern
Then remove that extern
You’re clearly missing the point.
Ok, I understand now.
maybe this will help you
https://book.mql4.com/variables/types
If it is not what you are looking for then you will not get an "elegant" solution according to your "thoughts". That is not how it works.
There is a reason why in MQL5 the "extern" was abandoned and you should also as a good practice not use it in MQL4+ either. You should be using "input" instead which cannot be modified within the code, forcing you use a different logic process. So consider using "input" and copying the data to globally scoped variables instead only during the initial placement but not to reinitialise those variables on a chart change.
Also, you can also use "unions" to store different data types in the Global Terminal Variables.
So consider using "input"
1st: Always do that and this the exception.
You have already been given the solution for using an extern variable input for your problem, but you decided it was not elegent....
what is not elegent about mapping to a terminal Global Variable and checking for it on start is beyond me, you clearly want some magical solution that does not involve any coding, or are you not understanding what is being said to you.
if you want to preserve variable values through different scenarios like symbol/timeframe change or restart then you have to store and recall them appropriately terminal GVs are the easiest to implement but you can also use other methods such as data files, there is no other way to ensure complete and correct control.
maybe you should define elegent because using a GV would be invisible to the user it does not get much simpler than that, although I would say that changing extern/inputs to control an EA that is already running is actually very inelegent and clumsy given the capabilities of MQL and the terminal.
elegant - adjective
I’ve never been a big fan of GVs. Yes, very subjective, I know, about just as much as what someone considers elegant.
We can help you better if you could elaborate:
1. What are your expectations for an elegant solution?
2. What's not elegant about GVs (and doubles, although they're irrelevant so long as the original data type can be typecasted)?
Your proposed solution of using a button would be elegant, but only if the user needs to be able to set the value of var OR if they need to know the value of var.
However, if they don't, or if you're just checking for the existence and state of the button to set/get the value, then creating a button seems unnecessary and would consume more time than a Global Variable.
Side note: if the only values of the var variable you'll be using are 0 and 1, you should be using bool instead of int, but that's for you to decide.
Another option, if you are looking to have persistent data (which is either complex in form or large in quantity), is to consider saving it to a file, to be read when you need to restart.
Global Terminal Variables are also stored in a file but cached in memory and can be accessed from multiple instances of EAs, Scripts and Indicators on the same terminal.
Also, please be aware of the difference between globally scoped variables and Global Terminal Variables. If you are only looking to persist data between chart changes then globally scoped variables should do the job, but for persisting data across recompilations or terminal restarts, then Global Terminal Variable or files is the better option as globally scoped variables will no longer have the saved data.