Close deal instead of position - page 2

 
doshur:

I hope to bring this up again because some strategy I use need to close individual order instead of the whole position.

Can MQ give some info??? 

Create a new order, opposite direction of your deal, with same volume. (Please don't double posts).
 
RaptorUK:

You cannot close an Order,  you can delete a Pending Order.  You can place an Order and once it is executed it becomes a deal,  that deal may create, add to or subtract from a position.  

If you are using and discussing MT5/mql5 you must use the correct terminology if you want to communicate effectively:  Orders, Positions and Deals in MetaTrader 5

so sorry, its deal...

can close individual deals??? 

 
angevoyageur:
Create a new order, opposite direction of your deal, with same volume. (Please don't double posts).

but I just want to close the order in profit

any workaround?? 

 
doshur:

but I just want to close the order in profit

any workaround?? 

If you take 2 containers each holding a gallon of water and empty them both into a 5 gallon container and mixed them well.  Some time later how would you go about extracting just the water in one of the original gallons of water ?
 
doshur:

so sorry, its deal...

can close individual deals??? 

There are no individual deals . . .  you need to read the information at the link I gave and understand the consequences.  This isn't mql4,  there are no open orders except pending orders,  a deal is a transitory thing,  it transits the order to the position,  you cannot close a deal.  To close the equivalent of a position opened/added to with 0.34 lots close 0.34 lots of your open position.
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
 

I think I have a solution to it. If you are coding an expert advisor. Use an array to store the deal details as it is made one by one and close each deal as and when required using the same array information.

Instead of depending on the terminal to provide you the deal details, you can create a similar array table by yourself and track the price movements.

 

I hope this will be helpfull! 

 
enivid:
Yes, of course. The average entry price may be changed only with entry, not exit.

I think average price will change with both entry and exit.

1 lots @ 2

1 lots @ 3

1 lots @ 4

average price = (2+3+4)/3 = 3

close 1 lot.

considering if @ 2 FIFO based closed the average = (3+4)/2=3.5

considering if @ 3 LIFO based closed the average = (2+4)/2 = 3

considering if @ 4 is closed the average = (2+3)/2 = 2.5

Thats a lot of difference, a difference if ending in a profit/loss. I guess we all want to be in profit, so accuracy of calculation is very important.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants - Documentation on MQL5
 
AmitJamuda:

I think I have a solution to it. If you are coding an expert advisor. Use an array to store the deal details as it is made one by one and close each deal as and when required using the same array information.

Instead of depending on the terminal to provide you the deal details, you can create a similar array table by yourself and track the price movements.

 

I hope this will be helpfull! 

but if the software got restarted, all the data will be gone.

secondly the average price in the position will used instead of the deal open price.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants - Documentation on MQL5
 
AmitJamuda:

I think I have a solution to it. If you are coding an expert advisor. Use an array to store the deal details as it is made one by one and close each deal as and when required using the same array information.

Instead of depending on the terminal to provide you the deal details, you can create a similar array table by yourself and track the price movements.

 

I hope this will be helpfull! 

You are right, this is the only solution if you need to manage several trades.
 
AmitJamuda:

I think average price will change with both entry and exit.

1 lots @ 2

1 lots @ 3

1 lots @ 4

average price = (2+3+4)/3 = 3

close 1 lot.

considering if @ 2 FIFO based closed the average = (3+4)/2=3.5

considering if @ 3 LIFO based closed the average = (2+4)/2 = 3

considering if @ 4 is closed the average = (2+3)/2 = 2.5

Thats a lot of difference, a difference if ending in a profit/loss. I guess we all want to be in profit, so accuracy of calculation is very important.

No, you are wrong. Open price don't change when you "close" part of a position.
Reason: