Profit calculation of closed orders "HELP" - page 3

 
Vitaly Muzichenko:
It does not fit, there is no information for 10 years.

It's not the same for you either.

The t variable will change and you'll be aghtung.

It has to be memorised before you start closing the series

color ProfitColor;
datetime t;


// START //
//t=TimeCurrent();//разместить в блоке сигнала на закрытие серии ордеров

   if(LastProfitCL(-1)<0) ProfitColor=Red;
   if(LastProfitCL(-1)>0) ProfitColor=LimeGreen;
   if(LastProfitCL(-1)==0)ProfitColor=DarkGray;
   ObjectCreate("Last Profit", OBJ_LABEL, 0, 0, 0);
   ObjectSet("Last Profit", OBJPROP_CORNER, 1);
   ObjectSet("Last Profit", OBJPROP_XDISTANCE, 5);
   ObjectSet("Last Profit", OBJPROP_YDISTANCE, 15);
   ObjectSetText("Last Profit",StringConcatenate("Last Profit: ",DoubleToStr(LastProfitCL(-1),2)),10,"Arial",ProfitColor);
// END START //

//+----------------------------------------------------------------------------+
//|    Возвращает суммарный профит в валюте депозита серии закрытых ордеров    |
//+----------------------------------------------------------------------------+
double LastProfitCL(int op=-1){ //"op" позиция (-1 любая позиция)
  double LastProfit=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 (OrderType()!= op || OrderSymbol()!= Symbol() || OrderMagicNumber()!= magic) continue;
    
       if (op<0 || OrderType()==op)

        {

          if(OrderCloseTime()>=t)LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();
       }

       }
  return(LastProfit);
   }

 
Renat Akhtyamov:

It's not the same for you either.

The t variable will change and you'll be aghast.

It has to be memorized before the series closes.

Have you tried it?

It's memorized before closing, at the moment the signal to close.

 
Vitaly Muzichenko:
It is not suitable, there is no information for 10 years.

Current profit, , all history.

By the way, it can be set to any date and time.

 
Vitaly Muzichenko:

Try


Comment( LastProfitCL(-1, 0) );

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

 return(LastProfit);
}

Profit remembers every new one, but then something counts unknown. In screen #3 it should be 4, not 190

 
Vitaly Muzichenko:

Have you tried it?

It remembers before it closes, at the moment the closing signal is received

Just read the code.
 

That, too, 190

if(OrderCloseTime()>=t)LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();
 
Natashe4ka:

Profit remembers every new one, but then something counts unknown. In screen #3 it should be 4, not 190

Here's the code, it works fine for me, but maybe because the series is closed correctly

Files:
info.mq4  9 kb
 
Natashe4ka:

So also 190

if(OrderCloseTime()>=t)LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();


Where is the command to close orders located?

Did you write the variable t in there?

t=TimeCurrent();//разместить в блоке сигнала на закрытие серии ордеров
 
Renat Akhtyamov:

Where is the command to close orders located?

Have you written the variable t in there?

t=TimeCurrent();//place in the signal block for closing a series of orders

It's all there of course.

if(t<=OrderCloseTime()) {
       t=OrderCloseTime();
if(OrderCloseTime()>=t)LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();
 
Natashe4ka:

It's all there, of course.

if(t<=OrderCloseTime()) {
       t=OrderCloseTime();
if(OrderCloseTime()>=t)LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();


No, this line is removed. This is already a profit calculation, it won't work that way.

Where the command to close in the code - there, but not such a line

Read above.

Reason: