如何检查一个订单是否已被平仓止损 - 页 7

 
Francesco Fava:

我正在编写一个EA,修改我为MT4编写的EA。我使用OrderSend打开一个订单。

简单地说,如果我需要了解(从历史上看),如果发送的订单(顺便说一下....,我必须检查订单,交易或位置?),已经被关闭,因为它已经达到了StopLoss。
我在论坛上检查过,但我没有找到我需要的东西....。

使用HistoryOrderGetDouble,参数为ENUM_ORDER_PROPERTY_DOUBLE

订单_价格_当前

只给出了订单符号的当前价格

不能与ORDER_SL 比较。我想ORDER_PRICE_CURRENT只是符号的当前价格,而不是订单的收盘价

谢谢大家的支持。

#include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006

void OnStart()
{
  for (int i = OrdersHistoryTotal() - 1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && (OrderType() <= OP_SELL))
    {
      OrderPrint();
      Print(EnumToString(OrderCloseReason()));
      
      if (OrderCloseReason() == DEAL_REASON_SL)
        Print("StopLoss!");      
    }
}


结果

#76922 2018.01.17 18:36:39 buy 1.00 EURUSD 1.22274 1.22273 0.00000 2018.01.17 18:36:47 1.22274 -12.22 0.00 0.00 [sl 1.22273] 0
DEAL_REASON_SL
StopLoss!
#76920 2018.01.17 18:27:29 sell 1.00 EURUSD 1.22376 0.00000 1.22375 2018.01.17 18:27:44 1.22375 -12.24 0.00 1.00 [tp 1.22375] 0
DEAL_REASON_TP
#875577 2018.01.17 18:27:43 buy 1.00 EURUSD 1.22375 0.00000 0.00000 2018.01.17 18:27:43 1.22375 0.00 0.00 0.00 0 expiration 2018.01.17 18:27:43
DEAL_REASON_TP
#76912 2018.01.17 16:49:24 sell 1.00 EURUSD 1.22233 0.00000 0.00000 2018.01.17 16:49:25 1.22237 -12.22 0.00 -4.00 0
DEAL_REASON_CLIENT
#76493 2018.01.11 08:35:00 buy 1.00 EURUSD 1.19462 0.00000 0.00000 2018.01.15 01:28:32 1.21962 -12.07 -8.48 2500.00 0
DEAL_REASON_CLIENT
#76492 2018.01.11 08:34:58 sell 1.00 EURUSD 1.19458 0.00000 0.00000 2018.01.15 01:28:32 1.21967 -12.07 2.04 -2509.00 0
DEAL_REASON_CLIENT
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Deal Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Deal Properties
  • www.mql5.com
A deal is the reflection of the fact of a trade operation execution based on an order that contains a trade request. Each trade is described by properties that allow to obtain information about it. In order to read values of properties, functions of the Identifier of a position, in the opening, modification or closing of which this deal...
 

关于交易、自动交易系统和测试交易策略的论坛

最后两笔订单

fxsaber, 2017.12.23 11:02

#include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006

// Возврат тикетов последних Amount-сделок, закрытых по Reason-причине
int GetLastHistoryPositions( long &Tickets[], int Amount = INT_MAX, const ENUM_DEAL_REASON Reason = DEAL_REASON_SL )
{
  int Count = ArrayResize(Tickets, 0);
  
  for (int i = OrdersHistoryTotal() - 1; (i >= 0) && (Count < Amount); i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && (OrderCloseReason() == Reason))
      Tickets[ArrayResize(Tickets, ++Count) - 1] = OrderTicket();
  
  return(Count);
}

void OnStart()
{
  long Tickets[];
  
  // Последние две сделки, закрытые по SL
  for (int i = GetLastHistoryPositions(Tickets, 2) - 1; i >= 0; i--)
    Print(Tickets[i]);
}


MT4的附加组件

enum ENUM_DEAL_REASON
{
  DEAL_REASON_CLIENT,
  DEAL_REASON_SL,
  DEAL_REASON_TP
};

ENUM_DEAL_REASON OrderCloseReason( void )
{
  return((StringFind(OrderComment(), "[sl]") != -1) ? DEAL_REASON_SL :
         ((StringFind(OrderComment(), "[tp]") != -1) ? DEAL_REASON_TP : DEAL_REASON_CLIENT));
}