# MT5 P/L and open trade calculations

489

How do calculate the above:

For example, if I start by placing a trade of lets say 5 lots of EURUSD then on the in the toolbox under the trade tag I can see the order type, the price the order was placed at, the current  price & current P/L.

Now if I sell 0.01 lots of EURUSD I can see the lots change to 4.99 but the price that the 5 lot order was placed at changes to what I assume is arrived at by some sort of averaging algorithm - how do I calculate this new price?

Now I assume that having sold 0.01 lots, then the overall P/L stays as current price x lots * 100000. But how is the P/L of the sold 0.01 lots calculated? I assume this is the difference between the averaged price and the current price x lots x 100000, is this correct?

If I purchase addition lots what are the calculations then (assume the reverse?)

Finally, how do I get the averaged price returned to my EA?

I hope you can understand what I am asking

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
Moderator
33504

BigAl:

How do calculate the above:

For example, if I start by placing a trade of lets say 5 lots of EURUSD then on the in the toolbox under the trade tag I can see the order type, the price the order was placed at, the current  price & current P/L.

Now if I sell 0.01 lots of EURUSD I can see the lots change to 4.99 but the price that the 5 lot order was placed at changes to what I assume is arrived at by some sort of averaging algorithm - how do I calculate this new price?

Now I assume that having sold 0.01 lots, then the overall P/L stays as current price x lots * 100000. But how is the P/L of the sold 0.01 lots calculated? I assume this is the difference between the averaged price and the current price x lots x 100000, is this correct?

If I purchase addition lots what are the calculations then (assume the reverse?)

Finally, how do I get the averaged price returned to my EA?

I hope you can understand what I am asking

Read this and tell us if that help.
489

angevoyageur:
Read this and tell us if that help.
thats good, thanks
489

angevoyageur:
Read this and tell us if that help.
Thanks again but you can tell me if I can actually return the average price to my EA rather then keeping track of it myself.
Moderator
33504

BigAl:
Thanks again but you can tell me if I can actually return the average price to my EA rather then keeping track of it myself.
Sorry but I don't understand your question, maybe because of the time change in Europe ;-)
489

angevoyageur:
Sorry but I don't understand your question, maybe because of the time change in Europe ;-)
OK - The current price of a position is the average price of all the trades conducted on a single position (say EURUSD). that averaged price is displayed on the trades tab of the toolbox just to the right of the Volume. Is there a way of accessing this average price from an EA (something like myaveragedprice = EURUSDpositionaveragedprice) yes (lol) very clumsy example but I hope it helps explain what I am asking
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
Moderator
18036

BigAl:
OK - The current price of a position is the average price of all the trades conducted on a single position (say EURUSD). that averaged price is displayed on the trades tab of the toolbox just to the right of the Volume. Is there a way of accessing this average price from an EA (something like myaveragedprice = EURUSDpositionaveragedprice) yes (lol) very clumsy example but I hope it helps explain what I am asking
You don't mean the current price,  that is Bid,  I assume you mean the averaged Position Open Price ?  Wouldn't you use PositionGetDouble()  with POSITION_PRICE_OPEN  don't forget to select the position first using  PositionSelect()
Moderator
33504

BigAl:
OK - The current price of a position is the average price of all the trades conducted on a single position (say EURUSD). that averaged price is displayed on the trades tab of the toolbox just to the right of the Volume. Is there a way of accessing this average price from an EA (something like myaveragedprice = EURUSDpositionaveragedprice) yes (lol) very clumsy example but I hope it helps explain what I am asking
Obviously you can access all the info seen on MT5 interface with MQL5. See RaptorUk answer.
489

RaptorUK:
You don't mean the current price,  that is Bid,  I assume you mean the averaged Position Open Price ?  Wouldn't you use PositionGetDouble()  with POSITION_PRICE_OPEN  don't forget to select the position first using  PositionSelect()
Thanks
489

angevoyageur:
Obviously you can access all the info seen on MT5 interface with MQL5. See RaptorUk answer.

Cheers