Two Things Every Forex Trader Ought To Know About MT4 Scripts

Some things you should know about Metatrader Scripts

Running a MT4 script is easy. Simply double click the Metatrader script or drop it on the chart of your choice.

Confirmation (or lack of it)

property show_confirm

Unless a particular property called show_confirm is set within the MT4 Script's code, after double clicking your script within the MT4 Navigator pane, the script will run immediately. If you want to run your MT4 script immediately, you don't need to do anything special.

If you wish to add a confirmation box (example show_confirm picture above) to your MT4 script when it runs so that you don't accidentally undo the work of several months in a single double click, copy the code below into the top section of your MT4 script. To comment out the line put two double forward slashes // in front of the # sign. The property for adding a confirmation box after double clicking a MT4 script is listed below:

#property show_confirm  // comment out this line to eliminate the confirmation box

Editing Inputs

property show_inputs

By default in a MT4 script, there are no editable inputs from the Metatrader terminal. There is an exception that can be added to a MT4 script if you would like to have a box pop up that includes the inputs after you double click before the script runs. It is the show_inputs property and use of this property disables the show_confirm property. You can include this property as follows:

#property show_inputs // comment out this line to eliminate showing inputs

Unlike an MT4 indicator or expert advisor where you can edit the inputs by right clicking on your forex chart, with MT4 scripts, you may need to get your hands dirty and edit the code if you aren't using the show_inputs property in your MT4 script.

If you wish to edit inputs for a particular script (if it has inputs) then you will need to right click on the script from the Navigator window and select Modify.Once the MetaEditor opens up you will see something like the following snippet. The thing to keep in mind is that the editable inputs are placed BEFORE the int start() function. In the code below, editable inputs include Lots, stoploss, takeprofit, Slippage and MagicNumber.

#property show_confirm  // comment out this line to eliminate the confirmation box
// #property show_inputs // comment out this line to eliminate showing inputs
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
// edit these values as desired below:
extern double Lots =             0.01;
extern int stoploss =            20;
extern int takeprofit =          30;
extern int Slippage =            7;
extern int MagicNumber =         0;
int start()
  {
//----

Tip: To make a confirmation box pop up every time you double click a MT4 script or drop a script on a chart to run, simply comment out the line #property show_confirm and uncomment the line // #property show_inputs and you will be able to see and edit the inputs from within Metatrader! Shown below:

// #property show_confirm  // comment out this line to eliminate the MT4 confirmation box
#property show_inputs // comment out this line to eliminate showing inputs

Variable Type

One final thing to keep in mind is the variable type. Lots is declared as double: extern double Lots = 0.01;

As a result, you will need to make sure to enter your numbers as a double type. Best practice states that the double type requires a decimal place in MQL4. If you wanted to trade a 1 lot, you would write it as 1.0 and not as simply 1 within the MQL4 code. The int type can't handle decimals, so make sure to leave those out when declaring Slippage, for instance.

If you enjoyed this MT4 help tutorial, you might also enjoy reading a MQL4 Code Tutorial for Metatrader. Every trader needs to learn at least some MQL4 in order to perform the simple operations of modifying code inputs, commenting out a line of code and understanding how to read the code to know if it is executing your MT4 Indicators, Metatrader expert advisors and MT4 scripts properly.

Follow patrickmwhite on Twitter

For updates