Download the source code for the Expert Advisor Programming books below. Be sure to extract the files into the MQL4 or MQL5 folder of your MetaTrader data folder. Make sure that your ZIP program is set to preserve folder paths.

Hedging Update for Expert Advisor Programming for MetaTrader 5

If you purchased the first edition of the book, please read the “Hedging Addendum (First Edition).pdf” file in the source code download for an explanation of the changes made to MQL5 and to the source code to support hedging accounts.

If you are having trouble downloading the ZIP files below, check your Downloads folder first! Your browser may not inform you of completed downloads in Incognito or Private mode.

Older Versions

Frequently Asked Questions

I’m receiving the error 10030 ‘Unsupported filling mode’

There is a FillType() function in the CTrade class that can be used to change the fill type. Pages 110-111 in the MQL5 book describe how to call this method in the OnInit() handler to change the fill type.

Here are the valid values for the FillType() method:





This filling policy means that an order can be filled only in the specified amount. If the necessary amount of a financial instrument is currently unavailable in the market, the order will not be executed. The required volume can be filled using several offers available on the market at the moment.


This mode means that a trader agrees to execute a deal with the volume maximally available in the market within that indicated in the order. In case the the entire volume of an order cannot be filled, the available volume of it will be filled, and the remaining volume will be canceled.


This policy is used only for market orders (ORDER_TYPE_BUY and ORDER_TYPE_SELL), limit and stop limit orders (ORDER_TYPE_BUY_LIMIT, ORDER_TYPE_SELL_LIMIT, ORDER_TYPE_BUY_STOP_LIMIT and ORDER_TYPE_SELL_STOP_LIMIT ) and only for the symbols with Market or Exchange execution. In case of partial filling a market or limit order with remaining volume is not canceled but processed further.

For the activation of the ORDER_TYPE_BUY_STOP_LIMIT and ORDER_TYPE_SELL_STOP_LIMIT orders, a corresponding limit order ORDER_TYPE_BUY_LIMIT/ORDER_TYPE_SELL_LIMIT with the ORDER_FILLING_RETURN execution type is created.