Atigiu o STOP

 
Como saber que atingiu o stoploss?
 
abimael Silva:
Como saber que atingiu o stoploss?

Veja o resultado da operação: se for positivo presume-se que atingiu o TP e vice versa.

 
abimael Silva:
Como saber que atingiu o stoploss?

O Thiago respondeu correto, porém um trailng stop pode encerrar uma posição por SL com lucro, visualmente no histórico as colunas SL / TP ficam coloridas e num EA o atributo DEAL_REASON guarda o motivo da transação ter sido realizada.

 
Rogerio Giannetti Torres:

O Thiago respondeu correto, porém um trailng stop pode encerrar uma posição por SL com lucro, visualmente no histórico as colunas SL / TP ficam coloridas e num EA o atributo DEAL_REASON guarda o motivo da transação ter sido realizada.

Veja essas threads:

https://www.mql5.com/pt/forum/332344

e

https://www.mql5.com/pt/forum/329917

Acessar o último resultado da operação
Acessar o último resultado da operação
  • 2020.02.08
  • www.mql5.com
Gostaria de saber como eu poderia acessar o resultado da última operação pra saber se foi TP ou SL, teria alguma função que realizaria isso...
 

Obrigado amigos, mas acredito ter resolvido com esta função.



void OnTradeTransaction(const MqlTradeTransaction & trans,
                        const MqlTradeRequest & request,
                        const MqlTradeResult & result)
   {
      if (HistoryDealSelect(trans.deal))
      {
         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);
         if(EnumToString(deal_entry) == "DEAL_ENTRY_IN")
            {
               if(EnumToString(deal_reason) == "DEAL_REASON_EXPERT" && EnumToString(trans.deal_type) == "DEAL_TYPE_BUY")
                  {
                     Alert("Buy");
                  }
               else if(EnumToString(deal_reason) == "DEAL_REASON_EXPERT" && EnumToString(trans.deal_type) == "DEAL_TYPE_SELL")
                  {
                     Alert("Sell");
                  }
            }
         else if(EnumToString(deal_entry) == "DEAL_ENTRY_OUT")
            {
               if(EnumToString(deal_reason) == "DEAL_REASON_SL" && EnumToString(trans.deal_type) == "DEAL_TYPE_BUY")
                  {
                     Alert("Sell SL");
                  }
               else if(EnumToString(deal_reason) == "DEAL_REASON_SL" && EnumToString(trans.deal_type) == "DEAL_TYPE_SELL")
                  {
                     Alert("Buy SL");
                  }
               else if(EnumToString(deal_reason) == "DEAL_REASON_TP" && EnumToString(trans.deal_type) == "DEAL_TYPE_BUY")
                  {
                     Alert("Sell TP");
                  }
               else if(EnumToString(deal_reason) == "DEAL_REASON_TP" && EnumToString(trans.deal_type) == "DEAL_TYPE_SELL")
                  {
                     Alert("Buy TP");
                  }              
          }
      }      
}
 
abimael Silva:

Obrigado amigos, mas acredito ter resolvido com esta função.



Maravilha! O caminho era esse mesmo. 

 
Henrique Vilela #:

Maravilha! O caminho era esse mesmo. 

Ola eu estou recendo este erro ao tentar compilar alguem poderia me da uma ideia de como corrigir este erro 

Arquivos anexados:
erro_if.png  55 kb
 
genesclin #:

Ola eu estou recendo este erro ao tentar compilar alguem poderia me da uma ideia de como corrigir este erro 

A condicional esta flutuando no escopo global, põe ela dentro da função de evento OnTradeTransaction

Razão: