Hello,
How to know the current value of all my long positions on a product?
It's POSITION_PRICE_CURRENT ?
Thanks,
Pierre
What do you mean with *current value*?
POSITION_PRICE_CURRENT is like it self described the current price of a position.
On netting account this means the price of *ALL* long positions; exactly 1 position, there can not be more.
On hedge account, you need to loop over all long trades as there can be more then 1 position.
What do you mean with *current value*?
POSITION_PRICE_CURRENT is like it self described the current price of a position.
On netting account this means the price of *ALL* long positions; exactly 1 position, there can not be more.
On hedge account, you need to loop over all long trades as there can be more then 1 position.
Hi Enrique Dangeroux,
Thanks for your answer.
How I know by code it's a netting account ?
Take the magic number combined with the Symbol name and the order type and add up all profits to get the total.
Thanks Marco vd Heijden.
How I know by code it's a netting account ?
if ( AccountInfoInteger(ACCOUNT_MARGIN_MODE) == ACCOUNT_MARGIN_MODE_RETAIL_NETTING ) { Print("netting"); }
Pseudo-code, not tested.
CPositionInfo m_position; // trade position object . . . // calculate whether there is an open position int profitLossPts = 0; for(int i=PositionsTotal()-1;i>=0;i--) // returns the number of open positions { if(m_position.SelectByIndex(i)) { if(m_position.Symbol()==Symbol() && m_position.Magic()==m_magic) { // Long only if ( m_position.PositionType() == POSITION_TYPE_BUY ) { const double profitLossPts = (SymbolInfoDouble(Symbol(),SYMBOL_BID) - g_position.PriceOpen()) / Point(); totalProfitLossPts += profitLossPts; } } } } // Now convert to USD, e.g. double profitLossUSD = profitLossPts * valueOfPoint;
Pseudo-code, not tested.
MQL4 does not allow for netting accounts. I am programming an EA in MQL4, could anyone give me a code example of how to add up open long positions? Of importance to me would be,(how much do I own?)( what they are worth at the current price) (and what I paid for them).
Thank you. (I attached my query to this thread because I thought it to be relevant)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
How to know the current value of all my long positions on a product?
It's POSITION_PRICE_CURRENT ?
Thanks,
Pierre