Position Value for Entire Account

 

How might I accurately get the total Position Value for my entire account? I need the total Position Value for all open trades in the account for an EA I am working on (Expressed in the account's home currency). Could someone kindly point me in the right direction or provide example code?

I am quite surprised MQL4 does not allow for "Position Value" as a predefined function (under Account Information). Position Value is directly related to other predefined Account Information functions such as Free Margin, Leverage etc. It really should also be predefined.

Thank you very much for the assistance.

 
Canadian Trader:

How might I accurately get the total Position Value for my entire account? I need the total Position Value for all open trades in the account for an EA I am working on (Expressed in the account's home currency). Could someone kindly point me in the right direction or provide example code?

I am quite surprised MQL4 does not allow for "Position Value" as a predefined function (under Account Information). Position Value is directly related to other predefined Account Information functions such as Free Margin, Leverage etc. It really should also be predefined.

Thank you very much for the assistance.

What exactly is the "Position Value" you're referring to ?
 
Code2219 or probably 2319:
What exactly is the "Position Value" you're referring to ?

This is an OANDA account. Position Value as defined by OANDA is:

"Position Value: The value of your position(s) expressed in the current account's home currency."

https://www.oanda.com/shared/documents/third_party/FXTrade_Platform_User_Guide/Account_Summary.htm

 
Canadian Trader:

This is an OANDA account. Position Value as defined by OANDA is:

"Position Value: The value of your position(s) expressed in the current account's home currency."

https://www.oanda.com/shared/documents/third_party/FXTrade_Platform_User_Guide/Account_Summary.htm

Here is the code I've put together so far. Seems to be working correctly. Anything jumping out that looks wrong or could be streamlined?


int start()
{

double PreviousUnits=0;
double CurrentUnits=0;
double TotalUnits;
double PreviousPositionValue=0;
double CurrentPositionValue=0;
double TotalPositionValue;
double PositionValueAveragePrice;
string BaseCurrency;

for( int PositionValueSearch = 0 ; PositionValueSearch < OrdersTotal() ; PositionValueSearch++ )
{      
   if (OrderSelect( PositionValueSearch, SELECT_BY_POS, MODE_TRADES )==true)
   {
         BaseCurrency=SymbolInfoString(OrderSymbol(), SYMBOL_CURRENCY_BASE);
         PositionValueAveragePrice=((MarketInfo( StringConcatenate( BaseCurrency,AccountCurrency() ),MODE_ASK) + MarketInfo( StringConcatenate( BaseCurrency,AccountCurrency() ),MODE_BID))/2);

         PreviousUnits=TotalUnits;
         CurrentUnits=OrderLots()*100000;
         TotalUnits=PreviousUnits+CurrentUnits;
         
         PreviousPositionValue=TotalPositionValue;
         CurrentPositionValue=CurrentUnits*PositionValueAveragePrice;
         TotalPositionValue=PreviousPositionValue+CurrentPositionValue;

      } //End of "if"
   
   else // If existing order NOT found for Pair at Current Price.
   {
   }

} //End of "for"

   Alert ("Position Value: ",TotalPositionValue);

}
 
I multiplied the order units (OrderLots) by 100000 to normalize to an integer. I could see this method causing issues with currencies that are not 5 digits. Is there a better way to calculate this line to compensate for 3 digit (or other) currencies?
Reason: