English
中文
日本語
ID
Vietnam
한국어
Filipino
 
   学院导航

外汇MQL4中订单选择函数如何使用

MQL4 OrderSelect Function

成功下订单后,我们将需要收集有关订单的信息,尤其是在我们想要修改订单时。 在此 MQL4 OrderSelect 函数文章中了解如何获取订单信息以及如果您希望 EA 修改或关闭它,如何使用此函数。


所有这些都是通过 OrderSelect() 函数完成的。 要使用 OrderSelect(),我们可以使用订单的票号,或者我们可以遍历未结订单池并按顺序选择每个订单。


以下是 OrderSelect() 函数的语法:


bool OrderSelect(int Index, int Select, int Pool=MODE_TRADES)


为了便于参考,可以在下表中找到上述参数的说明:

ParamsDescription
Index我们要选择的订单的编号,或者在订单池中的位置。 Select 参数指示是哪一个。
Select一个常量,指示 Index 参数是票号还是订单池位置:
  • SELECT_BY_TICKET–  The value of the Index parameter is an order ticket number

  • SELECT_BY_POS–  The value of the Index parameter is an order pool position

Pool指示订单池的可选常量:挂单/未结订单或已关闭订单。
  • MODE_POOL–  By default, refers to the pool of currently opened orders

  • MODE_HISTORY– Examines the closed order pool (the order history)

下面是一个使用订单编号的 OrderSelect() 函数的示例。 它是为在买入订单发生后修改止损和获利而设置的:

if (OrdersTotalMagicOpen()==0 && OpenBuy==true)
{
ticket = OrderSend(Symbol(),OP_BUY,NormalizeDouble(Lots,LotDigits),
Ask,vSlippage,0,0,EAName, MagicNumber, 0, Green);
return (ticket);
if(ticket>0)
{
OrderSelect(ticket,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),Bid – Stop_Loss * vPoint, Ask+TakeProfit * vPoint,0,Green);
}
}

在上面的例子中,我们使用 OrderSelect() 来选择单号,然后将它与 OrderModify() 函数结合起来,这样我们就可以修改 StopLoss 和 TakeProfit。 这个例子对 ECN 经纪商特别有用。 在 ECN 经纪商中,您不能将止损和止盈值放在 OrderSend() 函数内的相应参数中。 相反,这些参数必须保持为 0。只有在下单后,订单止损和止盈才能通过 OrderSelect() 和 OrderModify() 函数修改,如上图所示。 虽然上面的 OrderSelect() 与 OrderModify() 函数相结合,但实际上可以部署一系列订单信息函数来检索有关订单的信息。 MLQ Reference 中有这些函数的完整列表。 以下是常用的订单信息函数列表:

FunctionsDescription
OrderSymbol()The symbol of the instrument that the order was placed on. 
OrderType()The type of order: buy or sell; market, stop or limit.
OrderOpenPrice()The opening price of the selected order.
OrderLots()The lot size of the selected order.
OrderStopLoss()The stop loss price of the selected order. 
OrderTakeProfit()The take profit of the selected order. 
OrderTicket()The ticket number of the selected order. 
OrderMagicNumber()The magic number of the selected order.