Close deal instead of position - page 3

 
doshur:

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.

AmitJamuda solution is the only way to do what you want in MT5/mql5, obvisouly it's not a trivial task and you have to manage persistance of the data.

Anyway what you want is to do the same as in MT4/mql4 with MT5/mql5. Why don't use MT4/mql4 then ? It's a lot more easy to do.

 
angevoyageur:

AmitJamuda solution is the only way to do what you want in MT5/mql5, obvisouly it's not a trivial task and you have to manage persistance of the data.

Anyway what you want is to do the same as in MT4/mql4 with MT5/mql5. Why don't use MT4/mql4 then ? It's a lot more easy to do.

I understand. If only MT4 strategy tester is as fast as MT5 then it would make things a lot easier and faster.
 
angevoyageur:
No, you are wrong. Open price don't change when you "close" part of a position.

Please study the example closely. The open price is unchanged, Its the average open price that is changing.

See the difference is average price considering that one of the deal is closed. 

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
 
doshur:

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.

if you are concerned about the software getting restarted, use a file instead of an array.
 
AmitJamuda:

Please study the example closely. The open price is unchanged, Its the average open price that is changing.

See the difference is average price considering that one of the deal is closed. 

opps. I meant average open price.

for example

i open two deal at 100 and 50. Price now is at 75 and I decide to close the deal open at 50. My profit will be 0 right? 

 
AmitJamuda:

Please study the example closely. The open price is unchanged, Its the average open price that is changing.

See the difference is average price considering that one of the deal is closed. 

That makes no sense. There is only 1 position with an open price who is calculated by averaging price of deals with in direction. When you make a deal with out direction, P/L is calculated by the difference between the open price of the position and the price of the out deal. The volume of the position is reduced by the volume of this out deal and the open price doesn't change.
 
doshur:

opps. I meant average open price.

for example

i open two deal at 100 and 50. Price now is at 75 and I decide to close the deal open at 50. My profit will be 0 right? 

Seems you still don't understand what is a deal, you can said that a deal is open or close, that makes no sense. A deal has a direction, it can be in or out (or in/out but keep it simple). A deal with in direction add to your actual position, the open price of the position is then calculated by averaging price. A deal with out direction reduced your position and open price doesn't change.

In your example, your P/L depends of the direction of your position/deal. Do you have a buy or a sell position at 75 ? Do you have a new deal at 50 which is in or out direction ?

Position
Deal
Results
 BUY at 75
 DEAL at 50 = BUY (IN)
 Position BUY at new averaged price. No P/L
 BUY at 75
 DEAL at 50 = SELL (OUT)
 Position BUY at unchanged price. P/L=-25 * lot size
 SELL at 75
 DEAL at 50 = BUY (OUT)
 Position SELL at unchanged price. P/L=+25 * lot size
 SELL at 75
 DEAL at 50 = SELL (IN)
 Position SELL at new averaged price. No P/L
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
 
angevoyageur:

Seems you still don't understand what is a deal, you can said that a deal is open or close, that makes no sense. A deal has a direction, it can be in or out (or in/out but keep it simple). A deal with in direction add to your actual position, the open price of the position is then calculated by averaging price. A deal with out direction reduced your position and open price doesn't change.

In your example, your P/L depends of the direction of your position/deal. Do you have a buy or a sell position at 75 ? Do you have a new deal at 50 which is in or out direction ?

Position
Deal
Results
 BUY at 75
 DEAL at 50 = BUY (IN)
 Position BUY at new averaged price. No P/L
 BUY at 75
 DEAL at 50 = SELL (OUT)
 Position BUY at unchanged price. P/L=-25 * lot size
 SELL at 75
 DEAL at 50 = BUY (OUT)
 Position SELL at unchanged price. P/L=+25 * lot size
 SELL at 75
 DEAL at 50 = SELL (IN)
 Position SELL at new averaged price. No P/L

Terms aside. Lets use layman terms.

In my given example. I buy at price 100 (1 lot) and at 50 (1 lot). My average open price would be 75 correct?

When the price is at 75 and I decided to close 1 lot. For the closed position of 1 lot, my profit would be 0 correct?

 
Yes
 
doshur:

Terms aside. Lets use layman terms.

If you do not use the correct terms you cannot communicate effectively . . . 

Orders, Positions and Deals in MetaTrader 5 

Reason: