HOW DO I INPUT NEW DATA FROM USER AFTER THE EA HAS DONE THE WORK?

 

Hi,

I'm trying to program an EA. I want to scale out a part of the trade. Not closing it but changing the stop loss to a very close level (n pips). So, if the market comes back those n pips, it will close partially the trade. If not it will allow continue running. It should ask the user how many pips distance and how many lots should it close. I think I know how to do it.

After that, when the position is already partially closed, it should go again to get new data from the user in order to manage the next block of lots. That is where I need help. I need the EA to begin from the beginning asking the user for new inputs, and I dont know how. Could someone help me?

Thanks in advance

 

A cheap way to do this would be to make the variables global variables like the following:

         GlobalVariableSet("Stop_Loss", StopLoss);

It won't ask the user anything, but the user can update anytime they want and the EA will just collect that value based on whatever it is at the time it is told to read that variable.

I use this method when I want to frequently change values to evaluate actual results during forward testing.

 
carlosmb wrote >>

Hi,

I'm trying to program an EA. I want to scale out a part of the trade. Not closing it but changing the stop loss to a very close level (n pips). So, if the market comes back those n pips, it will close partially the trade. If not it will allow continue running. It should ask the user how many pips distance and how many lots should it close. I think I know how to do it.

After that, when the position is already partially closed, it should go again to get new data from the user in order to manage the next block of lots. That is where I need help. I need the EA to begin from the beginning asking the user for new inputs, and I dont know how. Could someone help me?

Thanks in advance

EA is generally used for trading unattended. If you want the EA to be interactive while running, the user need to right click to bring up the indicator properties to change the input parameters. Each time you change the parameters, the EA will run init() again and then each tick will call anything in the start() function repeatedly. What you are saying is to have something like a Message Box poping up if certain criteria are met so it will WAIT for the user to click OK or enter something. However, if the user is away from the PC, the EA will stop working while waiting for user input unless the control is returned to the EA at some point (kinda defeats the purpose of automated trading). My suggestion is to set up predefined entry and exit rules in a CSV file. This way the user can always change the configurations outside of MT4 as the CSV file will be re-read on each tick.

 
apparelink wrote >>

EA is generally used for trading unattended. If you want the EA to be interactive while running, the user need to right click to bring up the indicator properties to change the input parameters. Each time you change the parameters, the EA will run init() again and then each tick will call anything in the start() function repeatedly. What you are saying is to have something like a Message Box poping up if certain criteria are met so it will WAIT for the user to click OK or enter something. However, if the user is away from the PC, the EA will stop working while waiting for user input unless the control is returned to the EA at some point (kinda defeats the purpose of automated trading). My suggestion is to set up predefined entry and exit rules in a CSV file. This way the user can always change the configurations outside of MT4 as the CSV file will be re-read on each tick.

Thanks,

It is a very specific EA with news trading purposes, so I would always be there. I only want to aply a very little trailing stop to only a part of the position, and my broker doesnt allows that. So you are right, it is exactly that, I want to have something like a Message Box poping up if certain criteria are met so it will WAIT for the user to click OK or enter something. Then when I decide to give another close order, the EA should manage the trade again.

I thought about writing a script and calling it to the beginning when the criteria were met, but it wouldn't repeat the process with every tick. I could solve that with the funcion refreshdates(). In that case, with a loop refreshing the data and repeating the process till the criteria are met, and going back to the very beginning then, could work. Isnt it? To send it to the beginning could I call the function init() again from the deinit function? I' ve read that it shouldnt be done, but is the only solution I find.

Thanks again.

 
carlosmb:

I want to have something like a Message Box poping up if certain criteria are met so it will WAIT for the user to click OK or enter something.

Have you tried the MessageBox() function? This stops the EA's activity, waiting for user response, without locking up the MT4 terminal.