If you’re looking to have more flexibility with your forex expert advisor without having to write separate programs for various parameters or indicator settings, you can make your robot get external inputs with these simple steps.
Bear in mind that these inputs need to be made before the program is initialized so that the robot will already know the values before running the EA on a particular pair and time frame. This means that you will have to declare the external variables at the very beginning of the program, as MQL4 will have a pop-up window indicating the inputs right then.
Different data types such as integers, boolean, double, and string can be customized using external inputs. The modifier “extern” must be used before the variable declaration though, like so:
extern int TakeProfit = 100;
extern int StopLoss = 50;
extern int FastMA = 20;
extern int LotSize = 0.05;
I’m sure you’re wondering why values were already set for these external variables when these are supposedly input by the user at the start of the program. Well, these values are just there in case the user is too excited to start the EA that he forgets to change the parameters! That way, the forex robot won’t be drawing a blank or encountering an error while the program is already running.
To change the initial values, simply double click the value field beside the variable:
With these external inputs, you can simply use the variable names such as TakeProfit or StopLoss inside the functions instead of typing in actual values. If you want to adjust your profit target from 100 to 200 pips or your stop from 50 to 25 pips, having external inputs allows you to make the changes before running the EA instead of having to hunt for which lines of code to edit in your program. Easy, right?