user-defined inputs after initialization?

 

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.

 
billworld wrote:

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
 
ScottB wrote:
billworld wrote:

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

Cool Scott. I understand conceptually what you're doing, but, I'm still new to programming and MQL4. I don't know yet how to reference variables set in a separate EA. Could you kindly show a little code snippet on this? 

Thanks much!

Bill
 
billworld wrote:
ScottB wrote:
billworld wrote:

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

Cool Scott. I understand conceptually what you're doing, but, I'm still new to programming and MQL4. I don't know yet how to reference variables set in a separate EA. Could you kindly show a little code snippet on this?

Thanks much!

Bill
Bill

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
 
ScottB wrote:
billworld wrote:
ScottB wrote:
billworld wrote:

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

Cool Scott. I understand conceptually what you're doing, but, I'm still new to programming and MQL4. I don't know yet how to reference variables set in a separate EA. Could you kindly show a little code snippet on this?

Thanks much!

Bill
Bill

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
Thanks Scott. Since my last post I've been reading up on Global Variables and it's making lots of sense now. You have some good tips in both of your posts I wasn't aware of. Good stuff. And, I've now successfully created an accompanying EA which sets global variables which multiple instances of the primary EA use. This will be a real time saver when applying settings. For example, in my global EA I set the TimeZoneShift value which all other instances of the primary EA use. Saves having to retype the same info in property settings. And, if no global variable exists, I throw up an alert informing the user to be sure to apply the accompanying EA to a chart.

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
 
billworld wrote:

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.

Bill,

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
 
ScottB wrote:
billworld wrote:

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.

Bill,

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
 
billworld wrote:
ScottB wrote:
billworld wrote:

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.

Bill,

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

 
Good deal Bill, I sometimes do that sort of stuff just for fun. I am pretty new to MQL4 but have coded C, C++ and C# for years, so MQL4 came pretty easy to me. If I can be of any further help, email me anytime.

Scott
Reason: