How to count the number of trades that hit your stop loss or take profit target

 

After running the strategy tester, it gives you the number of winning and losing trades in the Report tab, but I want to know how many trades have hit my stop loss and how many trades have hit my take profit.

Because some trades will close without hitting SL or TP, like for example when reverse signal happen in MA crossover.

 

one way you could do it (assuming you know the ticket number of the deal): via HistoryDealGetInteger(ticketnumber,DEAL_REASON) with the different return options enlisted in ENUM_DEAL_REASON

https://www.mql5.com/en/docs/constants/tradingconstants/dealproperties#enum_deal_reason

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Deal Properties
Documentation on MQL5: 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...