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 ?
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
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); }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.