Hi there, the title says it all..In my EA (MT5) when the robot is closing position I want to check the profit of current position properly. I know there is a function "PositionGetDouble" but am not sure about how to use it properly. On my ECN account I pay commisions for each position opening cca. $2/lot + each position closing, totaling $4/lot. Besides that there may be positive or negative swap calculated.
So my question is how can I calculate my net profit for a certain position?
double x = PositionGetDouble(POSITION_PROFIT);
double y = PositionGetDouble(POSITION_SWAP);
Is variable "x" my net profit, or should I subtract variable "y" and commission which I don't yet know where to get from.
Please suggest, much thanks in advance for your help.
commission which I don't yet know where to get from.
Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий
Вопросы от начинающих MQL5 MT5 MetaTrader 5
fxsaber, 2016.10.29 17:09
Как узнать размер комиссии не открывая позицию по инструменту?
fxsaber, 2016.11.08 20:30
thanks fxsaber, but this way you are getting commision from previous deals which were closed. What if I don't have them yet, I'm trading multiple instruments with this EA, so there may be no done deals yet at the time I want to close my first one.
Besides, the question about how get "net profit" remains still open. Any other ideas, inputs, clarifications, much welcome.
Thanks in advance
Thanks I will, and will report back. In the meantime do you know what is included/excluded in
Much thanks again for your help.
Ok fxsaber was right, I can find deals from my current position, once I have the first deal, I can get it's commision and calculate commision on my position that way, cool.
I still haven't managed to find out about PositionGetDouble(POSITION_PROFIT), what it actually contans, I'll do some sample trades with my EA to clear this.
POSITION_PROFIT = POSITION_VOLUME * SYMBOL_TRADE_TICK_VALUE * (POSITION_PRICE_CURRENT - POSITION_PRICE_OPEN) / SYMBOL_TRADE_TICK_SIZE
ACCOUNT_PROFIT = ACCOUNT_EQUITY - ACCOUNT_BALANCE = Sum(POSITION_PROFIT[i] + POSITION_SWAP[i] + POSITION_COMMISSION[i])
Thanks fxsaber, I haven't checked that yet, but from the docs, I see that
SYMBOL_TRADE_TICK_VALUE=Value of SYMBOL_TRADE_TICK_VALUE_PROFIT
SYMBOL_TRADE_TICK_VALUE_PROFIT=Calculated tick price for a profitable position
What is now the a profitable position? Ok in other words, to make long story short, I can reduce question to this:
When I'm calculating net profit for a position which is still open, I use PositionGetDouble(POSITION_PROFIT), but I have to subtract Commision and Swaps? Is this right? Ok, Swaps can also be positive, but just I need just the principle.