Skip to main content


Showing posts from August, 2017

Checking Metatrader connectivity

When running Metatrader locally, the first action the platform does when it starts up is connecting to the near by broker server. You may it clearly by looking at the lower right part of the platform and checking the connectivity status:

In this case, you may see it is green and traffic is floating successfully between the terminal to the server. If from some reason, there is no connectivity, this terminal section would look like:

Manual solution

The manual solution is quite straightforward, mainly close and reopening the terminal. The challenge is knowing the connectivity got lost at the first place. When it happens, there is no way to tell unless you write the code which tells you the connectivity got lost. Once you know it happened, you need to restart the terminal and hope the problem got sorted out. If it continues, you can either scan the available serves or contact your broker.

Automated Connection monitoring

As noted above, it is challenging to know when the connectivity is lost if…

How to safely open an order in MQL4

All the functions discussed here are part of the Common library available for purchase.

In trading, it's critical to confirm certain criteria and conditions before opening an order. These checks may impact on your profitability or notify you in case something failed.

My checks

For me, it's important to verify before opening an order in MQL4 the following conditions:
- Is the spread acceptable? i.e. whether it's below a certain fixed value which I predefined.
- Is the trade context busy? This thread is the one which eventually opens the orders, if busy, it will not be possible to open the order anyway.
- Do we have enough margin to trade? As noted here, margin is critical factor when trading and could make a difference between a successful account to wiped one.
- Check open order returned value. As per MQL4 specifications, open order returns the order id which was opened or -1 in case it failed - It is a good practice to check the value bef…