Trader’s Tech – Writing Your Own EA Part 95 – OrderReliable

Forex Robot If you’re new to this series and want to check it out from the beginning, you can find that here. And look here for a list of all the programming articles.

In Part 94, we wrapped up our discussion of error trapping. As promised, we’ll talk a bit about the OrderReliable group of functions.I briefly touched on this subject when discussing generic start code. We’ll go into a little more detail this time.

Due to the quirkiness of MQL4 and MT4’s order handling functions, in 2006 (yeah, MT4 is THAT old) a gentleman by the name of Matthew Kennel started developing a group of functions to improve the handling of orders. This group of functions has gone through a lot of iterations since then. After quite a bit of searching, I can’t seem to find a version any newer than the one that I’m using, dated 01/07/2011 (OrderReliable_2011.01.07.mqh.) You can download a copy that version at my GitHub here. If anyone knows of a newer version, please share.

As I mentioned, OrderReliable is a group of functions in the form of a file that can be included near the top of your source code using the <#include …> preprocessor directive:

<#include OrderReliable_2011.01.07.mqh>


Be sure to place the file in the %MT4%/experts/include folder (where %MT4% represents the folder path of your MT4 installation.) OrderReliable_2011.01.07.mqh is MQL4 source code, so you can look at the functions in the MetaEditor. But don’t try to compile the file alone as that would be meaningless. It must be used as an include in your EA.

If you look at the include file, you will see four main functions (OrderSendReliable(), OrderModifyReliable(), OrderModifyReliableSymbol(), OrderCloseReliable()) and several utility functions (OrderReliableLastErr(), OrderReliableErrTxt(), OrderReliablePrint(), OrderReliable_CommandString(), OrderReliable_EnsureValidStop(), OrderReliable_SleepRandomTime(), OrderReSendReliable().) The only functions you will be calling from your code will be one or more of the main functions. The utility functions are written to be used by the main functions. Or course, that doesn’t mean you can’t use them in your code if you find a use for them.

For the purposes of this discussion, I won’t go into great detail about how these functions work. They are very elaborate and include quite a bit of error trapping. I can’t say that I would have written this code the way it’s written, but that’s why I say that programming is art and not science. I have little desire to re-invent the wheel, so I have been using these functions (successfully, I might add) for many years. When I started using them, I did so because, at the time,  I didn’t understand the intricacies of coding order handling routines for MQL4. I now have a very good understanding of that subject but I still find these functions very useful. I would be happy to answer specific questions about how these functions work. Otherwise, next installment I’ll start discussing how you can benefit from their use.

Thanks for your attention and please follow me on Twitter and LinkedIn.


The following two tabs change content below.
Winners Edge Trading was founded in 2009 and is working to create the most current and useful Forex information and training available on the internet.

Winner’s Edge Trading, as seen on:

Winner's Edge Trading in the news