Profit calculation of closed orders "HELP" - page 6

 
Aleksey Semenov:
If you have a terminal full of hundreds of unused glob variables, for example, then yes - the bulkhead will end sadly, if not, it works quite quickly, if written correctly
you can build your own log
 
Aleksey Semenov:
If, for example, your terminal is full of hundreds of unused glob variables, then yes - bulkheading will be sad, if not, it works quite fast if you write it correctly
I don't mind, but it's better to find easier ways if possible. Or we are not looking for easy ways) ?
 
Vitaly Muzichenko:
I don't mind, but it's better to find easier ways if possible. Or are we not looking for easy ways?
the main thing is to start writing yourself
 
Vitaly Muzichenko:
I don't mind, but it's better to find easier ways if possible. Or are we not looking for an easy way?
So where is the easy way, the question is still unresolved.
 

We still have not solved the problem, while this is a necessary function and many traders use it without knowing that it does not correctly calculate the profit of closed orders.
That is why a simple solution: LastProfit+=OrderProfit()+OrderCommission()+OrderSwap(); will not work and everyone keeps on screwing with history orders in their codes.

There is no competent solution even on the entire network - "google" says. So, it turns out that everyone uses the standard incorrect solution, or the correct one but the last order only?

 
Natashe4ka:

We still have not solved the problem, while this is a necessary function and many traders use it without knowing that it does not correctly calculate the profit of closed orders.
That is why a simple solution: LastProfit+=OrderProfit()+OrderCommission()+OrderSwap(); will not work and everyone keeps on screwing with history orders in their codes.

There is no competent solution even on the entire network - "google" says. So, it turns out that everyone uses the standard incorrect solution, or the correct one but the last order only?

We advised, you didn't get it....
 
Renat Akhtyamov:
We advised, you didn't understand....

OK, then let's break it down: there is a closing time of orders, there is a ticket or number of orders that coincide with the closing time. How do we combine and calculate the profit of these orders?
It seems to be simple, but we still don't understand.

 

It counts correctly, but only if 1-3 orders are closed, if more than 3, then the profit is with an unclear value.
What else can we add here?

//+----------------------------------------------------------------------------+
//     Возвращает суммарный профит в валюте депозита серии закрытых ордеров    |
//+----------------------------------------------------------------------------+
double LastProfitCL(int op=-1){ //"op" позиция (-1 любая позиция)
  double LastProfit=0;
  datetime t=0;
   for(i=OrdersHistoryTotal()-1;i>=0;i--)
     if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && (OrderType()==OP_BUY || OrderType()==OP_SELL) && OrderSymbol()==Symbol() && OrderMagicNumber()==magic) {
       if (OrderSymbol()!=Symbol()||OrderMagicNumber()!=magic) continue;
       if (t<OrderCloseTime()) {t=OrderCloseTime();}
       if ((op<0||OrderType()==op) && t==OrderCloseTime()) {LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();}
       }
  return(LastProfit);
   }
 
Natashe4ka:

It counts correctly, but only if 1-3 orders are closed, if more than 3, then the profit is with an unclear value.
What else can we add here?

//+----------------------------------------------------------------------------+
//     Возвращает суммарный профит в валюте депозита серии закрытых ордеров    |
//+----------------------------------------------------------------------------+
double LastProfitCL(int op=-1){ //"op" позиция (-1 любая позиция)
  double LastProfit=0;
  datetime t=0;
   for(i=OrdersHistoryTotal()-1;i>=0;i--)
     if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && (OrderType()==OP_BUY || OrderType()==OP_SELL) && OrderSymbol()==Symbol() && OrderMagicNumber()==magic) {
       if (OrderSymbol()!=Symbol()||OrderMagicNumber()!=magic) continue;
       if (t<OrderCloseTime()) {t=OrderCloseTime();}
       if ((op<0||OrderType()==op) && t==OrderCloseTime()) {LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();}
       }
  return(LastProfit);
   }

Have you ever tried to ask yourself "Why and what is written in my code?

I have already told you three times above what to do and how to do it.

You will not be able to move from the dead point otherwise you will not be able to do it.

 
Natashe4ka:

OK, then let's break it down: there is a closing time of orders, there is a ticket or number of orders that coincide with the closing time. How do we combine and calculate the profit of these orders?
It seems to be easy, but I still don't understand it.

Do you save all of this somewhere in a variable or in an array? Show us where you store it first, then we will see what to do next.
Reason: