손절매로 인해 주문이 마감되었는지 확인하는 방법 - 페이지 7

 
Francesco Fava :

저는 EA를 작성하고 있으며 MT4용으로 작성된 EA를 수정하고 있습니다. OrderSend를 사용하여 주문을 엽니다.

단순히 내가 이해해야 하는 경우(아마도 기록에서), 전송된 주문(그런데 .... 주문, 거래 또는 위치를 확인해야 함)이 StopLoss에 도달했기 때문에 마감되었습니다.
포럼에서 확인했지만 필요한 것을 찾지 못했습니다....

ENUM_ORDER_PROPERTY_DOUBLE 매개변수와 함께 HistoryOrderGetDouble 사용,

ORDER_PRICE_CURRENT

주문 기호의 현재 가격만 제공

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...
 

거래, 자동 거래 시스템 및 거래 전략 테스트에 관한 포럼

최근 2개 주문

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 ));
}
사유: