There might mathamatically be a sweeter way, but this is the way I would do it. You will always do your calc twice. Once for the base value ($98,760), and you are going to do it again to find the new value when the price moves (lets say price went up and it is now $98,800).
How you compare these values is conditional on the direction of the trade...
if Long.....change = new - base =98,800 - 98,760=40.
if Short....change =base-new=98,760-98,800=-40 (or you could do (longclac)*-1 =(98,800 - 98,760)*-1=-40)
new asset value is then base+change.
if you're long for this price move.. 98,760 + 40 =98,800
For short that is 98,760 + -40 =98.720
Does that make sense
OrderProfit() will give you change so just add that to your base asset value.
https://docs.mql4.com/trading/OrderProfit
V
Thanks Viffer.
I think that will help.
Hi folks,
I want to double and triple check my calcs please, I suspect I'm out somewhere in calculating my current holdings. The end goal is to have a base value of what I own. So the result is in $usd.
In this case it's a mini account so cLot = 10 000
Does anybody see a problem here ?:
dTotalCurrentLongPositionValue = dTotalCurrentLongPositionValue + OrderLots() * cLot * OrderOpenPrice() + OrderProfit();
dTotalCurrentShortPositionValue = dTotalCurrentShortPositionValue + OrderLots() * cLot * OrderOpenPrice() + OrderProfit();
- Don't hard code numbers (10 000) The change in account equity depends on the pair traded (including price if pair doesn't include your account currency, e.g. EURJPY with USD account) lot size (and size of a lot,).
OrderLots() * cLot * OrderOpenPrice() + OrderProfit()
OrderProfit IS the change, don't do both.- Either you sum OrderProfit() for all orders or you can sum (OrderClosePrice()-OrderOpenPrice()) * DIRorder * OrderLots() * perLotPerPoint
double equity.at.risk = 0; for(iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if ( OrderSelect(iPos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. ){ double DIRorder = Direction( OrderType() ), perLotPerPoint = PointValuePerLot( OrderSymbol() ); equity.at.risk += (OrderClosePrice()-OrderOpenPrice()) * DIRorder * OrderLots() * perLotPerPoint; } // For OrderSelect : double Direction(int op_xxx){ return( 1. - 2. * (op_xxx%2) ); } double PointValuePerLot(string pair=""){ /* Value in account currency of a Point of Symbol. * In tester I had a sale: open=1.35883 close=1.35736 (0.0147) * gain$=97.32/6.62 lots/147 points=$0.10/point or $1.00/pip. * IBFX demo/mini EURUSD TICKVALUE=0.1 MAXLOT=50 LOTSIZE=10,000 * IBFX demo/standard EURUSD TICKVALUE=1.0 MAXLOT=50 LOTSIZE=100,000 * $1.00/point or $10.0/pip. * * https://www.mql5.com/en/forum/127584 CB: MODE_TICKSIZE will usually return the * same value as MODE_POINT (or Point for the current symbol), however, an * example of where to use MODE_TICKSIZE would be as part of a ratio with * MODE_TICKVALUE when performing money management calculations which need * to take account of the pair and the account currency. The reason I use * this ratio is that although TV and TS may constantly be returned as * something like 7.00 and 0.0001 respectively, I've seen this * (intermittently) change to 14.00 and 0.0002 respectively (just example * tick values to illustrate). * https://www.mql5.com/en/forum/135345 zzuegg reports for non-currency DE30: * MarketInfo(Symbol(),MODE_TICKSIZE) returns 0.5 * MarketInfo(Symbol(),MODE_DIGITS) return 1 * Point = 0.1 * Prices to open must be a multiple of ticksize */ if (pair == "") pair = Symbol(); return( MarketInfo(pair, MODE_TICKVALUE) / MarketInfo(pair, MODE_TICKSIZE) ); // Not Point. }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi Folks,
I'm probably going to look like a right ass now, but I can't get this figured. Might be the flu that's fried the brain, but instead of hurting myself trying to figure this out I thought I'd ask.
I want to calculate the positions value.
So let's say I bought Eurusd 0.8 lots at 1.2345, the position value is Price x Lotsize = Value x 100000 to get the asset value.
So 1.2345 x 0.8 = 0.9876 x 100000 = $98 760
So the asset value is $98 760 dollars. If the value of Eurusd declines so does the asset value. If the value of Eurusd increases so does the asset value. Perfect.
But how do I calculate the same for shorts, where the inverse is true? And I don't suppose there's a function in MT4 that can calculate the value of a position?