Download MetaTrader 5
To add comments, please log in or register
Let your idle PCs do something useful. Join MQL5 Cloud Network!
Rasoul Mojtahedzadeh
25155
Rasoul Mojtahedzadeh 2015.02.11 14:56 

In order to calculate the total profit/loss of an open position, which one of the following equations is correct?

double pl = OrderProfit()+OrderCommission()+OrderSwap();

or

double pl = OrderProfit()-OrderCommission()+OrderSwap();
whroeder1
13590
whroeder1 2015.02.11 15:23  
I've only seen plus commission. Don't have a broker charging it so never have verified.
Rasoul Mojtahedzadeh
25155
Rasoul Mojtahedzadeh 2015.02.11 17:18  

If the value of OrderCommission() is always positive (which is not for OrderSwap()), then the second equation must be correct always:

double pl = OrderProfit()-OrderCommission()+OrderSwap();
honest_knave
947
honest_knave 2015.02.11 17:42  
Rasoul:

If the value of OrderCommission() is always positive (which is not for OrderSwap()), then the second equation must be correct always:

It's always negative for me:

 

If you have any doubt or variation between brokers, force it to be positive with fabs()

Rasoul Mojtahedzadeh
25155
Rasoul Mojtahedzadeh 2015.02.11 18:12  
honest_knave:

It's always negative for me:

If you have any doubt or variation between brokers, force it to be positive with fabs()


Thanks for providing real examples. Then I think the following equation must always work correctly:

double pl = OrderProfit()-MathAbs(OrderCommission())+OrderSwap();
Alain Verleyen
Moderator
28518
Alain Verleyen 2015.02.14 12:39  
Rasoul:


Thanks for providing real examples. Then I think the following equation must always work correctly:

No it's not. Your first proposal is the good one.
honest_knave
947
honest_knave 2015.02.14 12:48  

Well, let's cut to the chase... I think the confusion has come from "only seen plus commission [in formula]" being interpreted as "value of OrderCommission() is always positive".

Unless your broker pays you a commission for each trade (if so, please give me your broker's details!) it is going to be a negative number.

In which case just add them all together.

However, if somebody has found a broker anomaly which shows a charged commission as a positive number, then fabs() is one way to deal with it. Whether that causes issues with refunded commissions etc I have no idea.

/
To add comments, please log in or register