- Questions about MQL4
- Trailing Stop after Partial Close
- get ticket number for partially closed orders
- The original ticket number is the closed one. A new ticket number has the remaining lots.
- Same as original
- You need something persistent (files, global variables w/flush) that will stop the close on subsequent ticks. A variable or count will be lost on terminal restart. I use: if SL is at BE or higher trail, otherwise move SL to BE and then partial close.
- The close amount must be a multiple of Lot Step and be at least Min Lot. The remaining lots must also be at least Min Lot.
@Dominik Egert Remember that this is MQL4 and not MQL5! In MQL4 they are all Orders. There are no positions and deals here. Just pending Orders and Market orders.
When a Market Order is partially closed, it is split into two orders. One continues active with the rest of the volume, while another is created with the volume that was closed and placed in the history.
Since both cannot have the same ticket number, one of them gets a new ticket number and the other keeps the original ticket number.
Unfortunately I no longer remember which keeps the original number, but my instinct says the the remaining open order keeps the original ticked.
I will have to test this to confirm.
@Dominik Egert Remember that this is MQL4 and not MQL5! In MQL4 they are all Orders. There are no positions and deals here. Just pending Orders and Market orders.
When a Market Order is partially closed, it is split into two orders. One continues active with the rest of the volume, while another is created with the volume that was closed and placed in the history.
Since both cannot have the same ticket number, one of them gets a new ticket number and the other keeps the original ticket number.
Unfortunately I no longer remember which keeps the original number, but my instinct says the the remaining open order keeps the original ticked.
I will have to test this to confirm.
Thank you for your reply. I needed some light to this. Differences between MQL4 and MQL5 are obviously big.
Ive encountered already a few fundamental differences.
Thank you, thats why I asked.
The original ticket number is the closed one. A new ticket number has the remaining lots.
In the case of a computer crash or an abrupt MetaTrader terminal termination or anything unexpected happens causing the contents of the Global Terminal Variables never getting written to disk and being lost.
By "flushing" at regular intervals, you prevent the loss of data in case of such critical failures described. It can be done after a group update or individual updates, depending on how you are using them.
In the case of a computer crash or an abrupt MetaTrader terminal termination or anything unexpected happens causing the contents of the Global Terminal Variables never getting written to disk and being lost.
Yes, I know it can be confusing because they have similar names.
Globally scoped variables are part of the MQL language and are just normal variables defined outside of functions but only accessible within that program.
"Global Terminal Variable" are like a very simple external database of variables with a name or "key" (of String type) and a "value" (of Double type), and they are accessible from any program (EA, Indicator, Script) running under that MetaTrader terminal, but only last 4 weeks since their last access.
For more details please read the documentation:

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use