MQL5 TUTORIAL – SIMPLE BUY LIMIT EXPLAINED (in 3 minutes)

 

In this video, we are going to create an Expert Advisor that places a Buy Limit order when there are no open orders or positions.

 

Let’s see how we can do that. We start Metaeditor by clicking the little icon or pressing F4. We include the Trade mqh library by using the directive #include Trade\Trade.mqh, which provides trading functions. We create an instance of the CTrade class named trade. The On Tick function is called every time a new tick is received for the symbol. We get the ask price using Symbol Info Double with the SYMBOL ASK parameter and normalize it to the number of digits for the symbol using Normalize Double. We check if there are no open orders and no open positions by using Orders Total and Positions Total functions. If there are no open orders and no open positions, we place a Buy Limit order using the trade Buy Limit function.

 

The parameters for trade Buy Limit are: 0.10 for the lot size, Ask minus 200 points for the price of the Buy Limit order, Symbol to get the symbol, 0 for the Stop Loss, Ask plus 200 points for the Take Profit, ORDER TIME GTC for the expiration date, 0 for the expiration time, NULL for the comment.

 

We press F7 to compile the code.

 

If this was too fast for you or if you don’t understand what all the code is doing, you may want to check out the Premium course on our website, or watch one of the basic videos first. If the compilation works, we go back to MetaTrader by pressing F4 or clicking on the icon. Back in MetaTrader, we press Control and R to start the strategy tester, pick the Expert Advisor that we have just created, enable the visual mode, and start a strategy test. We should see the Expert Advisor on the chart. If you are already a Premium course member and have an idea for a video like this one, you can send us an email. We have learned how to create an Expert Advisor that places a Buy Limit order with a few lines of MQL code. Thanks for watching and I will see you in the next video.