Detect stop loss or take profit

 

Hello,

how to detect stop or take profit ? It seems that transaction is not providing this information.

This is a transaction protocol of a single in and out by stop loss:


HK      0       16:28:32.544    Core 1  2018.04.03 09:00:00   market sell 0.60 Ger30 sl: 12015.81 tp: 11958.61 (11987.51 / 11987.97 / 11987.51)
IK      0       16:28:32.544    Core 1  2018.04.03 09:00:00   deal #2 sell 0.60 Ger30 at 11987.51 done (based on order #2)
GI      0       16:28:32.544    Core 1  2018.04.03 09:00:00   deal performed [#2 sell 0.60 Ger30 at 11987.51]
DS      0       16:28:32.544    Core 1  2018.04.03 09:00:00   order performed sell 0.60 at 11987.51 [#2 sell 0.60 Ger30 at 11987.51]
JN      0       16:28:32.544    Core 1  2018.04.03 09:00:00   order_send=2 bar=3988 price=11987.51000000 sl=12015.81000000 tp=11958.61000000
HM      0       16:28:32.544    Core 1  2018.04.03 09:00:00   deal entry type=DEAL_ENTRY_IN
DS      0       16:28:32.544    Core 1  2018.04.03 09:00:00   deal entry type=DEAL_ENTRY_IN
PJ      0       16:28:32.544    Core 1  2018.04.03 09:00:00   deal entry type=DEAL_ENTRY_IN
LP      0       16:28:32.544    Core 1  2018.04.03 09:00:00   deal entry type=DEAL_ENTRY_IN
JE      0       16:28:32.544    Core 1  2018.04.03 09:06:40   stop loss triggered #2 sell 0.60 Ger30 11987.51 sl: 12015.81 tp: 11958.61 [#3 buy 0.60 Ger30 at 12015.81]
MR      0       16:28:32.544    Core 1  2018.04.03 09:06:40   deal #3 buy 0.60 Ger30 at 12015.81 done (based on order #3)
NK      0       16:28:32.544    Core 1  2018.04.03 09:06:40   deal performed [#3 buy 0.60 Ger30 at 12015.81]
KF      0       16:28:32.544    Core 1  2018.04.03 09:06:40   order performed buy 0.60 at 12015.81 [#3 buy 0.60 Ger30 at 12015.81]
NK      0       16:28:32.544    Core 1  2018.04.03 09:06:40   deal entry type=DEAL_ENTRY_IN
JQ      0       16:28:32.544    Core 1  2018.04.03 09:06:40   deal entry type=DEAL_ENTRY_IN
FG      0       16:28:32.544    Core 1  2018.04.03 09:06:40   deal entry type=DEAL_ENTRY_IN

And this is OnTransaction Code:

void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result)
  {

        ENUM_DEAL_ENTRY deal_entry=(int) HistoryDealGetInteger(trans.deal,DEAL_ENTRY);
        PrintFormat("deal entry type=%s",EnumToString(deal_entry));
}
 
DEAL_REASON
 

Hello,

this always returns DEAL_REASON_CLIENT.


This is the code:


void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result)
  {

        if(trans.symbol == Symbol())
        {
                ENUM_DEAL_ENTRY deal_entry=(ENUM_DEAL_ENTRY) HistoryDealGetInteger(trans.deal,DEAL_ENTRY);
                ENUM_DEAL_REASON deal_reason=(ENUM_DEAL_REASON) HistoryDealGetInteger(trans.deal,DEAL_REASON);
                PrintFormat("deal entry type=%s trans type=%s trans deal type=%s order-ticket=%d deal-ticket=%d deal-reason=%s",EnumToString(deal_entry),EnumToString(trans.type),EnumToString(trans.deal_type),trans.order,trans.deal,EnumToString(deal_reason));               
        }       
}
 
chinaski:

Hello,

this always returns DEAL_REASON_CLIENT.


This is the code:


You need to select the deal from history before accessing the properties.

See HistoryDealSelect().

 

Hi,

i changed the code to this:


if(HistoryDealSelect(trans.deal) == true)
{
     ENUM_DEAL_ENTRY deal_entry=(ENUM_DEAL_ENTRY) HistoryDealGetInteger(trans.deal,DEAL_ENTRY);
     ENUM_DEAL_REASON deal_reason=(ENUM_DEAL_REASON) HistoryDealGetInteger(trans.deal,DEAL_REASON);
     PrintFormat("deal entry type=%s trans type=%s trans deal type=%s order-ticket=%d deal-ticket=%d deal-       
                  reason=%s",EnumToString(deal_entry),EnumToString(trans.type),EnumToString(trans.deal_type),trans.order,trans.deal,EnumToString(deal_reason));
}

The protocol answers:

deal-reason=DEAL_REASON_SL


Thank you

 
Thank you...
Reason: