Profit calculation of closed orders "HELP" - page 5

 
Natashe4ka:

This is also correct if "cnt" is set to zero, but then the value is again incomprehensible as in screenshot 3 (should be a profit value of 4.27)

double LastProfitCL(int op=-1){ //"op" позиция (-1 любая позиция)
  int cnt=0;
  double LastProfit=0;
   for(i=0;i<OrdersHistoryTotal();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 ((op<0 || OrderType()==op) && cnt==0) {LastProfit+=OrderProfit()+OrderCommission()+OrderSwap(); cnt++;} else {cnt=0;}
       }
  return(LastProfit);
   }

It's not good when I do not have logical thinking(

You see, in the real market the deposit will melt in 3 days with this kind of logic.

 
Vitaly Muzichenko:
It's bad when you don't think logically(

That's right.

The pending order was deleted

 
Natashe4ka:

That's right.

The pending order has been deleted

It's understandable as it is.
 

OK, then how do you return a ticket of closed orders that are equal to OrderCloseTime() and calculate their profit?
Like this:

if (t<OrderCloseTime()) {t=OrderCloseTime();r=OrderTicket();profit+=OrderProfit()+OrderCommission()+OrderSwap();}
 
Natashe4ka:

OK, then how do you return a ticket of closed orders that are equal to OrderCloseTime() and calculate their profit?
Something like this:

if (t<OrderCloseTime()) {t=OrderCloseTime();r=OrderTicket();profit+=OrderProfit()+OrderCommission()+OrderSwap();}


What if it closes on a stop?

ticket=OrderClose(......);

if(ticket>0){//увеличить размер массива на один и записать тикет закрытого ордера}

 
I wrote a system for recording accumulated drawdown or profit - it looked something like this: for each market order during the opening a global variable with the ticket name of this order is created and when we need to recalculate the accumulated profit/loss, we just check the current list of orders against the list of global variables and make a count by deleting unnecessary variables and adding the profit directly to the ticket name.
 
Renat Akhtyamov:

What if it closes on a stop?

ticket=OrderClose(......);

if(ticket>0){//увеличить размер массива на один и записать тикет закрытого ордера}

Well, what arrays, what tickets, what orders?

After the first restart of the terminal, or shutdown over the weekend, you will simply lose all the data, and that will be the end of all the writing and calculations.

 
Aleksey Semenov:
For example, when I was writing for myself the system of counting accumulated drawdown or profit, it looked like this: for each market order during the opening a global variable with the ticket name of this order is created and when we want to recalculate the profit/loss, we simply check the current order list against the list of global variables and perform the calculation by deleting the excess variables and adding the profit directly to the ticket from the name.

This is a heavy load on the system, in an indicator it works fine, but in an EA the enumeration of a dozen global variables may cause the terminal to freeze.

There is an opening and closing time, you have to work with it, and there is no difficulty in getting it, and with one time record you can get all the information about the state of the account, and you don't need a bicycle.

 
Vitaly Muzichenko:

What arrays, what tickets, what orders?

After the first restart of the terminal, or a weekend shutdown, you will simply lose all the data, and that will be the end of all the writing and calculations.

it's solvable

I don't have to explain it to you.

 
Vitaly Muzichenko:

This is a heavy load on the system, in an indicator it works fine, but in an EA the enumeration of dozens of global variables can end up with a hang of the terminal.

There are opening and closing times, that's what you need to work from, and there's no difficulty in getting it, with one time record you can get all the information about the state of the account, and you don't need a bicycle.

If you have for example a terminal full of hundreds of unused glob variables then yes - the rebuild will end sadly, if not then it works quite quickly, if written correctly