-
Notifications
You must be signed in to change notification settings - Fork 12
/
buy_order.mq5
24 lines (21 loc) · 1.12 KB
/
buy_order.mq5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#define EXPERT_MAGIC 123456 // MagicNumber of the expert
void OnStart()
{
//declare and initialize the trade request and result of trade request
MqlTradeRequest request={0};
MqlTradeResult result={0};
// parameters of request
request.action =TRADE_ACTION_DEAL; // type of trade operation
request.symbol =Symbol(); // symbol
request.volume =1.2; // volume of 0.1 lot
request.type =ORDER_TYPE_BUY; // order type
request.price =SymbolInfoDouble(Symbol(),SYMBOL_ASK); // price for opening
request.deviation=5; // allowed deviation from the price
request.magic =EXPERT_MAGIC; // MagicNumber of the order
//send the request
if(!OrderSend(request,result))
PrintFormat("OrderSend error %d",GetLastError()); // if unable to send the request, output the error code
//information about the operation
PrintFormat("retcode=%u deal=%I64u order=%I64u",result.retcode,result.deal,result.order);
Print("ORDER PLACED!");
}