STEP 8 – Define your order to buy or sell

How do we open a Buy or Sell order?

To open an order, you must understand how MQL5 does it.

Basically MQL5 has a builtin OrderSend() function.

Inside the Metatrader Help you will find this entry


bool  OrderSend(MqlTradeRequest&  request
MqlTradeResult&   result


Okay, now we know that we have to handle a request and a result. But how can we put that knowledge into action?

First we need to declare an MqlTradeRequest like this:

MqlTradeRequest myrequest;

Let’s assume we want to buy what is on the current chart. It should be a market order of 0.1 Lot (not less) without a Stop Loss or a Take Profit. If price moves more than 20 points, we don’t want to buy anymore.

How do we translate that wish into programming code?

There is a request type for that called ORDER_TYPE_BUY

myrequest.type = ORDER_TYPE_BUY;

it should be a market order

myrequest.action = TRADE_ACTION_DEAL;

We want no StopLoss and no Take Profit now =0 ; =0 ;

that order should only take place within a slippage of 20 points

myrequest.deviation =20;


We want to buy what is on the current chart

myrequest.symbol = _Symbol;

and we want only 0.1 Lot

myrequest.volume = 0.1;

and if we get filled, we want only to get filled with the requestet LotSize all at once (Could come in handy once you start to trade a few thousand lots a day)

myrequest.type_filling = ORDER_FILLING_FOK;

That was not to hard to understand, was it?

Another hint: you might need to add this code if you get the “failed exchange buy invalid request error

ZeroMemory (myresult);



In STEP9 we will create a complete function that does exactly what we want…