How to know the current value of all my long positions on a product?

 

Hello,

How to know the current value of all my long positions on a product?

It's POSITION_PRICE_CURRENT ?

Thanks,

Pierre

Productivity - USA - MetaTrader 5
Productivity - USA - MetaTrader 5
  • www.metatrader5.com
The productivity index measures the output produced for each hour of labor worked. This indicator is useful for predicting inflation and output growth. If the cost of labor increases respective to the increase of productivity, and, moreover, if the increase in production costs is unlikely, then it will not cause inflation. It has a significant...
 
Pierre Rougier:

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.

 
Take the magic number combined with the Symbol name and the order type and add up all profits to get the total.
 
Enrique Dangeroux:

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 ?

 
Marco vd Heijden:
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.

 
Pierre Rougier:

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;
 
Thanks Anthony, your are the best.  😊
 
Anthony Garot:

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)