Changing extern variables - page 2

 
Route206 #:

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

 
Daniel Cioca #:

Then remove that extern

You’re clearly missing the point. 
Please re-read original post. 
“0” is default and OK. 
“1” is needs to be manually set when applicable and then EA to reset to “0” upon execution and kept at “0” when chartchange etc. 
 
Route206 #:
You’re clearly missing the point. 
Please re-read original post. 
“0” is default and OK. 
“1” is needs to be manually set when applicable and then EA to reset to “0” upon execution and kept at “0” when chartchange etc. 

Ok, I understand now.

maybe this will help you

https://book.mql4.com/variables/types

Types of Variables - Variables - MQL4 Tutorial
Types of Variables - Variables - MQL4 Tutorial
  • book.mql4.com
Types of Variables - Variables - MQL4 Tutorial
 
Route206 #: I'm afraid that is not the elegant solution i'm looking for. I need to set execute simple routines when EA is running, using GlobalVariables and Doubles is not that. Maybe i should consider buttons...

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.

 
Fernando Carreiro 

So consider using "input"

1st: Always do that and this the exception. 
2nd: I like to believe there is an elegant way for an EA to take manual (or external) input to do certain things (Buy, Sell, Hedge etc) and that not everything is driven by chart events. 
Triggering that with an extern variable change would have worked for me, if resetting the value would have actually ‘sticked’ through a chartchange, recompile etc. 
 
Route206 #:
1st: Always do that and this the exception. 
2nd: I like to believe there is an elegant way for an EA to take manual (or external) input to do certain things (Buy, Sell, Hedge etc) and that not everything is driven by chart events. 
Triggering that with an extern variable change would have worked for me, if resetting the value would have actually ‘sticked’ through a chartchange, recompile etc. 

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

  1. 1.
    graceful and stylish in appearance or manner.
 
I’ve never been a big fan of GVs. Yes, very subjective, I know, just about as much  as what someone considers elegant or not. 
So I guess I’m merely looking for alternatives to extern and GVs. 
As for the inelegance of manual intervention: exceptional cases are simply difficult to code I think. JPY is today’s example for mean reversal strategies. 
 
Route206 #:
I’ve never been a big fan of GVs. Yes, very subjective, I know, about just as much  as what someone considers elegant. 
So I guess I’m merely looking for alternatives to extern and GVs. 
As for the inelegance of manual intervention: exceptional cases are simply difficult to code I think. JPY is today’s example for mean reversal strategies. 

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.

 
Route206 #: So I guess I’m merely looking for alternatives to extern and GVs. 

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.

 
Thanks. 
Let’s not discuss elegancy. Life is too short.  ;-)
I’ll try the button and yes, there are more values than 0 and 1 for my case. 
Sorry for throwing everyone for a loop. 
Reason: