Question about partially close order

 
Hi guys, I'd like to create an EA that use partially close order. This is the first time I try to create an EA with partially close order. There's some questions that I have regarding this matter. 

So the questions is:
1. If I partially close an order does the existing order receive new order ticket?

2. If it is receive new ticket order how it affect stoploss and or trailing stoploss?

3. How to code effectively (or efficiently) stop EA to partially close order for the second time (the second time should be close all position). Should I use, like a count variable to determine if it's already do partially code or not? 

 
  1. The original ticket number is the closed one. A new ticket number has the remaining lots.
  2. Same as original
  3. 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.
  4. 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.
 
Question to point 1.

An existing order?? Changes??
Combined with closing volume??

What???

I think orders, pending orders and positions are mixed up, or not?

I expected a position receiving a modify order (pending or market) changing volume, would not change the ticket number on the position, but generate at creation of the order a new ticket number for this order.

Is this wrong?

 
Dominik Egert:
Question to point 1.

An existing order?? Changes??
Combined with closing volume??

What???

I think orders, pending orders and positions are mixed up, or not?

I expected a position receiving a modify order (pending or market) changing volume, would not change the ticket number on the position, but generate at creation of the order a new ticket number for this order.

Is this wrong?

@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.

 
Fernando Carreiro:

@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.

 
Fernando Carreiro: Unfortunately I no longer remember which keeps the original number, but my instinct says the the remaining open order keeps the original ticked.

The original ticket number is the closed one. A new ticket number has the remaining lots.

 
William Roeder: The original ticket number is the closed one. A new ticket number has the remaining lots.
Thanks for clearing that up!
 
William Roeder
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.
Thanks william for the tips. May I ask why we need to use flush? Personally this is the first time I heard about that and do I need to use the flush on every global variable?
 
Luandre Ezra: Thanks william for the tips. May I ask why we need to use flush? Personally this is the first time I heard about that and do I need to use the flush on every global variable?

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.

 
Fernando Carreiro:

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.

Thanks Fernando for the explanation. Can you tell me what's the difference between GV using global set variable with global variable when we initialize variable on the global scope? Is it difference or the same?
 
Luandre Ezra: Can you tell me what's the difference between GV using global set variable with global variable when we initialize variable on the global scope? Is it difference or the same?

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:

Reason: