How does HistoryDealGetInteger() in backtest?

 

If you can help me resolve this situation, please let me know.

I was thinking about the process after StopLoss in OnTradeTransaction(). I wrote the following code.

When I backtested with this code, it did not work as expected. The reason was that HistoryDealGetInteger() only returned 0 no matter what property I specified.

So I used GeLastError() to check the error code and it returned ErrorCode4755. This is the error code for a missing transaction history.

However, in the MT5 log, there is a log where StopLoss is triggered and a deal ticket is issued, and the OnTraderTransaction() instruction is executed, so there should be transaction history.

1) Does HistoryDealGetInteger() not work during backtesting?

2) I would like to know if there is a solution to this problem.
void OnTradeTransaction(const MqlTradeTransaction& trans, const MqlTradeRequest& request, const MqlTradeResult& result)
  {

//---
   if (trans.type == TRADE_TRANSACTION_DEAL_ADD)
     {
      ulong deal_ticket = trans.deal;
      if (HistoryDealGetInteger(deal_ticket, DEAL_REASON) == DEAL_REASON_SL)
        {
         //-----Here Process
        }
     }
  }

2) I would like to know if there is a solution to this problem.

OOP in MQL5 by Example: Processing Warning and Error Codes
OOP in MQL5 by Example: Processing Warning and Error Codes
  • www.mql5.com
The article describes an example of creating a class for working with the trade server return codes and all the errors that occur during the MQL-program run. Read the article, and you will learn how to work with classes and objects in MQL5. At the same time, this is a convenient tool for handling errors; and you can further change this tool according to your specific needs.
 

You need to select the history before dealing with it using HistoryDealGetIntege() or similar functions.


Documentation on MQL5: Trade Functions / HistoryDealSelect
Documentation on MQL5: Trade Functions / HistoryDealSelect
  • www.mql5.com
Selects a deal in the history for further calling it through appropriate functions. It returns true if the function has been successfully completed...
 
Alain Verleyen #:

You need to select the history before dealing with it using HistoryDealGetIntege() or similar functions.


Thank you for helping me.

I tried to use HistorySelect(), and it worked!

But HistoryOrderSelect(ulong ticket) didn't work.:(


Anyway, my code works well. Thank you for your information.:)

 
MoukemasSu #:
HistoryOrderSelect

Probably you mixed up deals and orders. Also please note, that orders can be active (not in the history yet), then you need to call OrderSelect instead.