Why the trade comment changes to [sl] or [tp] in MT5
Short answer: the broker's server rewrites the comment when a position is closed by Stop Loss or Take Profit. The MT5 help says so: "a comment to an order can be changed by a broker or server. For example, if a position is closed by Stop Loss or Take Profit, the corresponding information is displayed in the comment." On the closing record, your EA's text is replaced by something like [sl 1.08350] or [tp 1.08900].
So don't use the comment to identify trades. Use the magic number as the ID, and the comment only as a label you read while the trade is open. This guide covers what gets rewritten, how to tell why a trade closed, and what to rely on instead.
What you see in the History tab
Open the Toolbox (Ctrl+T), go to History, and find a trade that hit its stop. If your EA opened it with the comment grid-A, the closing line can show [sl 1.08350] instead. A take profit shows [tp ...] with the price.
A user in an MQL5 forum thread describes the same thing: when a position closes by SL or TP, [sl xxx.xx] or [tp xxx.xx] is written in the comment field of the report instead of the original comment.
That is why a comment filter or a spreadsheet pivot on comments loses every trade that ended on a stop or a target.
Why the comment gets overwritten
The comment is a free-text field attached to the order. The MQL5 docs call it simply "Order comment" and give no guarantee about what happens to it afterwards. The MT5 help says the server may change it, and that the maximum length is 31 characters.
In practice:
- Stop Loss or Take Profit closes replace the text with
[sl ...]or[tp ...]. - Length is capped. The help gives a maximum of 31 characters.
- The broker decides. Servers can write different things, so a rule that works on one broker's history may fail on another's.
An MQL5 forum moderator puts it bluntly in another thread: "comments are not reliable (it can be changed by the broker)". Their advice there is to use a different magic number for each EA and symbol.
How to tell why a trade closed
If what you want is "which trades hit their stop", don't parse the comment text. A moderator in the forum thread above recommends the deal's reason field. MQL5 has DEAL_REASON, and the docs list these values:
| Value | Meaning |
|---|---|
DEAL_REASON_SL | Executed as a result of Stop Loss activation |
DEAL_REASON_TP | Executed as a result of Take Profit activation |
DEAL_REASON_EXPERT | Placed from an MQL5 program, such as an EA or script |
DEAL_REASON_CLIENT | Placed from a desktop terminal |
DEAL_REASON_SO | Executed as a result of a Stop Out |
The History tab has no column for it, so reading it takes a short MQL5 script or an EA. Because it is a value on the deal, the broker's wording doesn't affect it.
What to rely on instead
- The magic number is the ID. It is fixed when the position opens, and the deals that come from it carry it. See how to see the magic number of a trade.
- Give every EA, and every setfile you treat as separate, its own magic number. Then nothing depends on the comment.
- Keep comments short. Stay well under 31 characters. A short label like
trend-aggris easy to read in the Trade tab while the position is open. - Check your own broker. Switch the History tab to the Positions and Deals view (right-click, Statement) and compare the opening deal with the closing deal of a trade that hit its stop. What each one shows depends on your broker's server.
Reading comments while the trade is open
While a position is open, its comment is still what your EA sent. That is also when you most need to know which EA a floating loss belongs to.
DrawGuard records it at that point. A free EA on one chart sends the account's equity and every open position, with its symbol, magic number, comment and floating profit, every 60 seconds to a web dashboard. Every day, week and month is broken down by symbol, magic number and comment, so you can see which one caused each drawdown, and charts filter by the same. You can look at it on the live demo without signing up.
It records from the moment the EA connects. It does not rebuild floating drawdown from before that, and it never places or closes trades. For the full picture of splitting drawdown by EA, see drawdown per EA by magic number.
FAQ
Why does my MT5 trade comment show [sl] or [tp]?
The broker's server rewrites the comment when a position is closed by Stop Loss or Take Profit. The MT5 help says a comment can be changed by a broker or server, and gives this case as the example.
Can I stop the broker from changing the comment?
No. The change happens on the server, not in your EA. Use the magic number to identify trades and treat the comment as a label.
How long can an MT5 order comment be?
The MT5 help gives a maximum of 31 characters. Keep yours shorter, since the server can change the text afterwards.
How do I find which trades closed on a stop loss?
Read the deal's reason, DEAL_REASON_SL for a Stop Loss and DEAL_REASON_TP for a Take Profit, instead of matching text in the comment. The reason is stored as a value on the deal, so it doesn't depend on the broker's wording.