Why is this piece of code printing 3 times? It is not really a problem, but I want to eliminate it. Any suggestion? Thanks "

 
void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result)
  {
   ulong ticket;
   string symbol;

   if(!PositionSelect(_Symbol))
    {
  HistorySelect(0,TimeCurrent());

   for(int i=HistoryDealsTotal()-1;i>=0; i--)
      {
         ticket=HistoryDealGetTicket(i);
         symbol=HistoryDealGetString(ticket,DEAL_SYMBOL);
         if( symbol==_Symbol)
            {
              if(HistoryDealGetInteger(ticket,DEAL_REASON)==DEAL_REASON_SL)
                {
               double priceStlTriggered=HistoryDealGetDouble(ticket,DEAL_PRICE);
               Print("priceStlTriggered = ",priceStlTriggered);
                }
            }
            break;
      }
    }
  }





2021.03.23 17:23:17.232 2016.06.03 16:08:40   stop loss triggered #2 buy 8 WIN$D 69910 sl: 69780 [#3 sell 8 WIN$D at 69780]
2021.03.23 17:23:17.232 2016.06.03 16:08:40   deal #3 sell 8 WIN$D at 69780 done (based on order #3)
2021.03.23 17:23:17.232 2016.06.03 16:08:40   deal performed [#3 sell 8 WIN$D at 69780]
2021.03.23 17:23:17.232 2016.06.03 16:08:40   order performed sell 8 at 69780 [#3 sell 8 WIN$D at 69780]
2021.03.23 17:23:17.232 2016.06.03 16:08:40   priceStlTriggered = 69780.0
2021.03.23 17:23:17.232 2016.06.03 16:08:40   priceStlTriggered = 69780.0
2021.03.23 17:23:17.232 2016.06.03 16:08:40   priceStlTriggered = 69780.0
 
Daniel D.: Why is this piece of code printing 3 times? It is not really a problem, but I want to eliminate it. Any suggestion? Thanks

Please post only in English on this forum. Use the automatic translation tool if needed. Use simple language structure when using mechanical translation. 2013.08.09

 

Very sorry! I posted on the wrong forum. But if someone here can also answer I will like it very much. Thanks a lot.


" Why is this piece of code printing 3 times? It is not really a problem, but I want to eliminate it. Any suggestion? Thanks "

 
Daniel D. :


Help: OnTradeTransaction - several types of transactions are captured in the OnTradeTransaction function. The sequence of transactions is not regulated.

Documentation on MQL5: Event Handling / OnTradeTransaction
Documentation on MQL5: Event Handling / OnTradeTransaction
  • www.mql5.com
OnTradeTransaction - Event Handling - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: