How to enter a user-defined input after initialization?
For example, I need the datetime in the user input to represent CurTime() which
then the user can edit. The app would then operate on the user-edited time.
Is there a way to accomplish this?
Thanks
Bill
P.S. I know I could just "force" the user to only enter a time offset
value (e.g. offset from CurTime()) and operate off of that, but, that is not user-friendly
and can very easily lead to errors with user-defined settings.
How odd, I was just getting ready to start a thread about a technique I came up with on this very topic. I added a second expert advisor that does nothing but set global variables. The primary expert advisor gets its input values from the global variable rather than its own input.
You set the input value of the second expert advisor to the value you want the first one to use. This allows the user to actually interact with the first expert advisor while its running without causing a restart. You could even add logic to cause a message box to display periodically asking if the value should be reevaluated (for example at the end of a day or at a specific time interval).
I hope this helps.
Scott
How to enter a user-defined input after initialization?
For example, I need the datetime in the user input to represent CurTime() which
then the user can edit. The app would then operate on the user-edited time.
Is there a way to accomplish this?
Thanks
Bill
P.S. I know I could just "force" the user to only enter a time offset
value (e.g. offset from CurTime()) and operate off of that, but, that is not user-friendly
and can very easily lead to errors with user-defined settings.
How odd, I was just getting ready to start a thread about a technique I came up with on this very topic. I added a second expert advisor that does nothing but set global variables. The primary expert advisor gets its input values from the global variable rather than its own input.
You set the input value of the second expert advisor to the value you want the first one to use. This allows the user to actually interact with the first expert advisor while its running without causing a restart. You could even add logic to cause a message box to display periodically asking if the value should be reevaluated (for example at the end of a day or at a specific time interval).
I hope this helps.
Scott
How to enter a user-defined input after initialization?
For example, I need the datetime in the user input to represent CurTime() which
then the user can edit. The app would then operate on the user-edited time.
Is there a way to accomplish this?
Thanks
Bill
P.S. I know I could just "force" the user to only enter a time offset
value (e.g. offset from CurTime()) and operate off of that, but, that is not user-friendly
and can very easily lead to errors with user-defined settings.
How odd, I was just getting ready to start a thread about a technique I came up with on this very topic. I added a second expert advisor that does nothing but set global variables. The primary expert advisor gets its input values from the global variable rather than its own input.
You set the input value of the second expert advisor to the value you want the first one to use. This allows the user to actually interact with the first expert advisor while its running without causing a restart. You could even add logic to cause a message box to display periodically asking if the value should be reevaluated (for example at the end of a day or at a specific time interval).
I hope this helps.
Scott
Dang, I was guilty of doing just what I hate when others do - through years of programming experience, I know for a fact that any discussion that starts with "all you have to do is" is going to be impossible to understand at the practical (code) level.
Global variables are always doubles so I use the MathRound to convert them to an integer if I need a whole number otherwise you can get very odd errors that are causeed by the fact that a double may not be exactly an integer even if you set it to one (i.e. double d = 2 may produce a value of 2.00001 which won't test equal to 2)
the code to set a variable is:
GlobalVariableSet("ProfitTarget", 1.2825)
or you could write:
double someVariable = 1.2825;
GlobalVariableSet( "ProfitTarget", someVariable)
This is the code to get the variable:
double profitTarget = GlobalVariableGet("ProfitTarget");
returns a double of 1.2825
but to get at what I think you want to do, go into the client terminal and hit F3 which will bring up the global variables dialog. From here you can add new variables (remember they are always doubles) and set their values. I use this feature to change profit targets mid strategy so I don't have to have an arbitrary trailing stop routine but can use indicators, brain, etc. to say, hmmm, this is going to run, I am going to move my target.
and last you can write an expert advisor that takes input (#extern double myTarget = 1.2825 in the ea that accepts inputs) and sets the global variable by GlobalVariableSet("ProfitTarget", myTarget) and have your real expert advisor check the value using GlobalVariableGet("myTarget")); The advantage to the last approach is that you can change inputs in the first ea, have the second ea check for new values periodically and yet not have the second ea restart.
I hope this is clearer than my original answer.
Scott
How to enter a user-defined input after initialization?
For example, I need the datetime in the user input to represent CurTime() which
then the user can edit. The app would then operate on the user-edited time.
Is there a way to accomplish this?
Thanks
Bill
P.S. I know I could just "force" the user to only enter a time offset
value (e.g. offset from CurTime()) and operate off of that, but, that is not user-friendly
and can very easily lead to errors with user-defined settings.
How odd, I was just getting ready to start a thread about a technique I came up with on this very topic. I added a second expert advisor that does nothing but set global variables. The primary expert advisor gets its input values from the global variable rather than its own input.
You set the input value of the second expert advisor to the value you want the first one to use. This allows the user to actually interact with the first expert advisor while its running without causing a restart. You could even add logic to cause a message box to display periodically asking if the value should be reevaluated (for example at the end of a day or at a specific time interval).
I hope this helps.
Scott
Dang, I was guilty of doing just what I hate when others do - through years of programming experience, I know for a fact that any discussion that starts with "all you have to do is" is going to be impossible to understand at the practical (code) level.
Global variables are always doubles so I use the MathRound to convert them to an integer if I need a whole number otherwise you can get very odd errors that are causeed by the fact that a double may not be exactly an integer even if you set it to one (i.e. double d = 2 may produce a value of 2.00001 which won't test equal to 2)
the code to set a variable is:
GlobalVariableSet("ProfitTarget", 1.2825)
or you could write:
double someVariable = 1.2825;
GlobalVariableSet( "ProfitTarget", someVariable)
This is the code to get the variable:
double profitTarget = GlobalVariableGet("ProfitTarget");
returns a double of 1.2825
but to get at what I think you want to do, go into the client terminal and hit F3 which will bring up the global variables dialog. From here you can add new variables (remember they are always doubles) and set their values. I use this feature to change profit targets mid strategy so I don't have to have an arbitrary trailing stop routine but can use indicators, brain, etc. to say, hmmm, this is going to run, I am going to move my target.
and last you can write an expert advisor that takes input (#extern double myTarget = 1.2825 in the ea that accepts inputs) and sets the global variable by GlobalVariableSet("ProfitTarget", myTarget) and have your real expert advisor check the value using GlobalVariableGet("myTarget")); The advantage to the last approach is that you can change inputs in the first ea, have the second ea check for new values periodically and yet not have the second ea restart.
I hope this is clearer than my original answer.
Scott
However, while this solves a different problem I was eventually going to get to, it still doesn't solve the original problem on how to have the initial value for a user-defined input dynamically generated. For example, for a user-defined datetime input, I want to fetch the CurTime(). I tried setting CurTime() as a global in an accompanying EA and then calling the global from an extern input, but, you can't initilize an extern input with a global! So, I'm at a loss as to how to achieve what I'm after.
Also, why isn't there an ability to set a global string variable? I have a label I'd like to attach to each chart based on a text string, but, I'm not seeing a way to do it.
Thanks for the great input Scott.
Bill
How to enter a user-defined input after initialization?
For example, I need the datetime in the user input to represent CurTime() which
then the user can edit. The app would then operate on the user-edited time.
Is there a way to accomplish this?
Thanks
Bill
P.S. I know I could just "force" the user to only enter a time offset
value (e.g. offset from CurTime()) and operate off of that, but, that is not user-friendly
and can very easily lead to errors with user-defined settings.
My email address is scott.boulette@gmail.com. Feel free to email me (I am not great about checking it more than once a day) and I can give you a more in depth answer to some of these questions (I don't want to bore the forum). The order of things appears to be that the input dialog happens first even before the init() function, so you would never get an opportunity to set the extern variable. But now the hacker in me wants to see if I can find a way to do it, so I will keep you posted.
It would be way too much trouble but to get around the no string issue, you could enter a string array in your ea and use the user input of a value as the index into the array and then use that value. If it has to be totally dynamic and entered by a user, you could also write (or more likely get someone to write a dll for you which would accept string input and call that from your ea.
None of these are very good solutions but I will give this some thought. Today's musing has a way of being tomorrow's problem that must be solved.
Scott
How to enter a user-defined input after initialization?
For example, I need the datetime in the user input to represent CurTime() which
then the user can edit. The app would then operate on the user-edited time.
Is there a way to accomplish this?
Thanks
Bill
P.S. I know I could just "force" the user to only enter a time offset
value (e.g. offset from CurTime()) and operate off of that, but, that is not user-friendly
and can very easily lead to errors with user-defined settings.
My email address is mailto:scott.boulette@gmail.commailto:scott.boulette@gmail.com. Feel free to email me (I am not great about checking it more than once a day) and I can give you a more in depth answer to some of these questions (I don't want to bore the forum). The order of things appears to be that the input dialog happens first even before the init() function, so you would never get an opportunity to set the extern variable. But now the hacker in me wants to see if I can find a way to do it, so I will keep you posted.
It would be way too much trouble but to get around the no string issue, you could enter a string array in your ea and use the user input of a value as the index into the array and then use that value. If it has to be totally dynamic and entered by a user, you could also write (or more likely get someone to write a dll for you which would accept string input and call that from your ea.
None of these are very good solutions but I will give this some thought. Today's musing has a way of being tomorrow's problem that must be solved.
Scott
Thanks Scott. Looks like I reached some limits on MQL. The usage I have here isn't critical enough to go the dll and/or hacker route. Now that I understand the limits of using global variables, I'll just have to live with what I got.
Cheers
Bill
How to enter a user-defined input after initialization?
For example, I need the datetime in the user input to represent CurTime() which
then the user can edit. The app would then operate on the user-edited time.
Is there a way to accomplish this?
Thanks
Bill
P.S. I know I could just "force" the user to only enter a time offset
value (e.g. offset from CurTime()) and operate off of that, but, that is not user-friendly
and can very easily lead to errors with user-defined settings.
My email address is mailto:scott.boulette@gmail.commailto:scott.boulette@gmail.commailto:scott.boulette@gmail. commailto:scott.boulette@gmail.com. Feel free to email me (I am not great about checking it more than once a day) and I can give you a more in depth answer to some of these questions (I don't want to bore the forum). The order of things appears to be that the input dialog happens first even before the init() function, so you would never get an opportunity to set the extern variable. But now the hacker in me wants to see if I can find a way to do it, so I will keep you posted.
It would be way too much trouble but to get around the no string issue, you could enter a string array in your ea and use the user input of a value as the index into the array and then use that value. If it has to be totally dynamic and entered by a user, you could also write (or more likely get someone to write a dll for you which would accept string input and call that from your ea.
None of these are very good solutions but I will give this some thought. Today's musing has a way of being tomorrow's problem that must be solved.
Scott
Thanks Scott. Looks like I reached some limits on MQL. The usage I have here isn't critical enough to go the dll and/or hacker route. Now that I understand the limits of using global variables, I'll just have to live with what I got.
Cheers
Bill
Scott
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
How to enter a user-defined input after initialization?
For example, I need the datetime in the user input to represent CurTime() which then the user can edit. The app would then operate on the user-edited time.
Is there a way to accomplish this?
Thanks
Bill
P.S. I know I could just "force" the user to only enter a time offset value (e.g. offset from CurTime()) and operate off of that, but, that is not user-friendly and can very easily lead to errors with user-defined settings.