Comment in MT5 trading history report - page 2

 

Please don't offer solutions that are solely dependant on using your "MT4Orders" class. This is a MQL5 question, not MQL4 and it should be independent of 3rd party solutions.

 
Mitsuru:
I want to analyse each EA trading from the trading history report in MT5. If a position closed by SL or TP, [sl xxx.xx] or [tp xxx.xx] is written in comment field in the report instead of original comment. I don't know which EA trades the position. Is there any way to keep original comment which EA write?

Please don't rely on the "Comment" field as that can change. Instead, use the "reason" field of the closing deal or order for the position.

ENUM_DEAL_REASON

Identifier

Description

DEAL_REASON_SL

The deal was executed as a result of Stop Loss activation

DEAL_REASON_TP

The deal was executed as a result of Take Profit activation

ENUM_ORDER_REASON

Identifier

Description

ORDER_REASON_SL

The order was placed as a result of Stop Loss activation

ORDER_REASON_TP

The order was placed as a result of Take Profit activation

Below are references for the Deal "reason" for a stop-loss, but the same applies for Order "reason" property as well as the take-profit. Just search the MQL5 documentation.

Forum on trading, automated trading systems and testing trading strategies

MT5 Position History Information

Fernando Carreiro, 2023.02.07 17:35

  1. Select the History by the position identifier — HistorySelectByPosition
  2. Scan the Deals — HistoryDealsTotal, HistoryDealGetTicket
  3. Find the deals where the "reason" is hitting stop-loss. — HistoryDealGetInteger, DEAL_REASON = DEAL_REASON_SL
  4. Retrieve the deal price (i.e. stop-loss price) — HistoryDealGetDouble, DEAL_PRICE
EDIT: Attention! Depending on market/exchange type and/or filling mode, you have may multiple deals at different prices for hitting the stop-loss.
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
Deal Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro #:

Please don't offer solutions that are solely dependant on using your "MT4Orders" class. This is a MQL5 question, not MQL4 and it should be independent of 3rd party solutions.

Please do not impose your personal opinion.

Forum on trading, automated trading systems and testing trading strategies

Libraries: MT4Orders

fxsaber, 2021.06.02 10:09

the MetaQutoes has completely localized the latest update of the library into English. The latest build of the library is now available on the English page with comments in the source code translated into English.

All open source libraries are MQL5-libraries.

#property script_show_inputs

input long inTicket = 0; // Position Ticket

void OnStart()
{
  if (HistorySelectByPosition(inTicket))
    Alert(HistoryOrderGetString(HistoryOrderGetTicket(0), ORDER_COMMENT));
}
 
Mitsuru #:

I'm sorry but I don't understand which script. Could you put the script file?

This one or the other one.
 
fxsaber #: Please do not impose your personal opinion. All open source libraries are MQL5-libraries.

By giving the OP a solution using YOUR library (even if it is open source), you are the one imposing your personal opinion, forcing the user to depend on YOUR library.

Instead, one should strive to offer a solution that is only dependant on the official MQL5 documentation, that is an unbiased, allowing the user not to be dependant on any 3rd party.

 
fxsaber #:
This one or the other one.

Thank you for letting me know. But I cannot compile it well. I may resolve the issue tomorrow..  

I have a further question.

    PRINT(OrderComment());

It shows an orignal comment insted of [sl xx.xx]? 

 
Fernando Carreiro #:
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893

uum, i didn' think it was expert advisor and automated trading issue, but MT5 issue. Because EA and it's trading are working well.

There is the MT4 section but no MT5 one, so I posted it to General.

I accept your suggestion.


It's strange that there is MQL4/MT4 section but no MQL5/MT5 one. I think you should review it.

 
Mitsuru #:

Thank you for letting me know. But I cannot compile it well. I may resolve the issue tomorrow.. 

Try attached EX5-file.

I have a further question.

    PRINT(OrderComment());

It shows an orignal comment insted of [sl xx.xx]? 

Yes.

<ex5 removed by moderator, on mql5 file are allowed on this forum>

 
Mitsuru #: uum, i didn' think it was expert advisor and automated trading issue, but MT5 issue. Because EA and it's trading are working well. There is the MT4 section but no MT5 one, so I posted it to General.

I accept your suggestion.

I based it on your opening sentence ... " I want to analyse each EA ", but don't worry about it too much! Some times questions are somewhat ambiguous and it is difficult to decide in which section they belong.

Everything on the forum is geared towards MT5/MQL5, except for a single section at the end which is reserved for the older MT4/MQL4.

 
Fernando Carreiro #:

By giving the OP a solution using YOUR library (even if it is open source), you are the one imposing your personal opinion, forcing the user to depend on YOUR library.

Instead, one should strive to offer a solution that is only dependant on the official MQL5 documentation, that is an unbiased, allowing the user not to be dependant on any 3rd party.

We have different points of view. I do not impose my point of view on you and do not believe that it is the only correct one.