Open Order Script for MT4

Opening an order is quite a simple process with MetaTrader 4: you click New Order, select the instrument, position size, stop-loss, and take-profit and bang! The order will open. Although the process is already simple, we can still improve it and work around some limitations. The OpenOrder script can help you open orders with more options and more automation.

Two of the biggest limitations when you open an order with the default MetaTrader process are:

  • Manual calculation of the position size.
  • Inability to set the magic number.

As you may know, there are risk management rules to protect your account. One of these rules involves setting a stop-loss and calculating the position size depending on the money you are risking.

The other disadvantage is not being able to set a magic number for the order, resulting in limiting the possibility to manage the order with an expert advisor.

The above limitations can be worked around with the OpenOrder script. The script allows you to set a percentage of balance that you are ready to risk and to calculate the position size depending on the stop-loss that you set. The script also has an option for you to set a magic number for the order and an optional comment.

You can download the script for educational purposes and test it on a demo account.

About MT4 Script Open Order

The parameters accepted by the script are:

  • Specify position size if you want to set a fixed size for your order. This parameter is ignored if the next one true.
  • True if you want to use the risk % to calculate the size.
  • % of available balance to risk — used in the calculation of the position size.
  • Type of order — can be BUY or SELL.
  • Take Profit in pips — if you want to set a take-profit price.
  • Stop Loss in pips — if you want to set a stop-loss price.
  • Magic number if you want to specify one.
  • Comment for the order if you want one.

Open Order Script - Input Parameters

The script can be very useful in some occasions. Also, it can show you an example of how to open an order if you are learning MQL4.

The script is free to download and use.

➥ Download OpenOrder Script

To install the script, please follow the instructions below:

  1. Download the script archive file.
  2. Open the MetaTrader 4 data folder (via File→Open Data Folder).
  3. Open the MQL4 Folder.
  4. Copy all the folders from the archive directly to the MQL4 folder.
  5. Restart MetaTrader 4 or refresh the list of scripts by right-clicking the Navigator subwindow of the platform and choosing Refresh.

You can also read a more detailed instruction on how to perform the installation.

Make sure you enable Allow live trading in the Common tab when executing this script and also in the platform's menu Tools→Options→Expert Advisors. Otherwise, it won't be able to open an order.

How to Enable Live Trading for Scripts in MT4?

If you are interested in building your own expert advisor or knowing more about how to do it, check our MT4 Expert Advisor Template.

© 2005–2023

Design — Mart Studio

Forex trading bears intrinsic risks of loss. You must understand that Forex trading, while potentially profitable, can make you lose your money. Never trade with the money that you cannot afford to lose! Trading with leverage can wipe your account even faster.

CFDs are leveraged products and as such loses may be more than the initial invested capital. Trading in CFDs carry a high level of risk thus may not be appropriate for all investors.