Calculating total profit or total loss
If your function works perfect, then, it will give you the total profit or loss ...
if in loss, for sure the value will be in negative.
This is my own function I use ... You may try it if you like ... It is almost the same like yours !
double Profit(){ double Pft=0; int total=OrdersTotal(); for (int cnt=0 ; cnt<total ; cnt++){ if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true) if(OrderMagicNumber()==magic && OrderSymbol()==Symbol() && (OrderType()==OP_BUY || OrderType()==OP_SELL)){ Pft = Pft + OrderProfit() + OrderCommission() + OrderSwap(); } } return(Pft); }
Osama Shaban:
thanks
If your function works perfect, then, it will give you the total profit or loss ...
if in loss, for sure the value will be in negative.
This is my own function I use ... You may try it if you like ... It is almost the same like yours !
how do i calculate total loss using a function similar to this one below
and if the Profit is negative(i.e trades are in loss) will the function below just return a negative value?
int BuyProfit ()
{ static int TotalBuyProfit = 0; for(int iPos= OrdersTotal()-1; iPos >= 0; --iPos) if(OrderSelect(iPos, SELECT_BY_POS) && OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol() && OrderType() == OP_BUY )continue; TotalBuyProfit = OrderProfit()+OrderSwap()+OrderCommission(); return (TotalBuyProfit);}