Profit calculation of closed orders "HELP" - page 8

 
Natashe4ka:
Orders are closed in series, but if there are no closing conditions, the orders are collected for a day or two, etc.

If the series is closed practically during one cycle, say, during the lifetime of one bar, then we can take the criterion of the series by the time of closing plus one bar. That is, all orders closing time of which is less than that should be discarded.

However, we have concerns that this will only work in the tester; any manual intervention will result in incorrect profit calculation (only EA's profit will be taken into account, while the manual trade will not).

 
Vitalie Postolache:
If the series is closed practically during one cycle, say, during the lifetime of one bar, then we can take the series criterion by the time of closing plus one bar. That is, all orders with the time of closing less than that should be discarded.

I.e.

if ((op<0||OrderType()==op) && (t==OrderCloseTime() ||  t==OrderCloseTime()+60)) {LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();}

(t==OrderCloseTime()||t==OrderCloseTime()+60)?

 
Natashe4ka:

I.e.

if ((op<0||OrderType()==op) && t==OrderCloseTime()+60) {LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();}

+60 ?

PeriodSeconds() would be more correct. Or are you going to work only on M1?

Something like this:

double lastloss()
{
double lastlos=0.0,op=0.0;
int cnt=0;
datetime time=0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
      {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==Magic && OrderType()<2)
         {
            if(cnt==0) time=OrderCloseTime();
            op=OrderProfit()+OrderSwap()+OrderCommission();
            if(OrderCloseTime()+PeriodSeconds()<time && op>0.0) break;
            lastlos+=op;
            if(cnt!=0) cnt++;
         }
      }
}
return(lastlos);
}
 
Vitalie Postolache:

Something like this:

This adds a new value to the previous value. But every new close, a new value of the profit.
 

And you can also number the orders in the comment, for those DCs who do not overwrite the comment. And when trying it out the number from the comment, as soon as the number is out of order - the series is over.

Example: Orders series number 1,2,3,4,5. Closed in order 5,4,3,2,1 - the loop sees 1 and interrupts. Closing in order 1,2,3,4,5 and 1 (the order number of the previous series) - the loop sees the difference 5-1>1 and aborts. I need to think how to translate this into code ))))

 
Natashe4ka:
So a new value is added to the previous value. And every new close, a new value of profit.
I don't know, it doesn't add up for me.
 
Vitalie Postolache:
I don't know, it doesn't add up for me.

Put the info on and you'll see it adds up.

color ProfitColor;

   if(lastloss()<0) ProfitColor=Red;
   if(lastloss()>0) ProfitColor=LimeGreen;
   if(lastloss()==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(lastloss(),2)),10,"Arial",ProfitColor);
 
Natashe4ka:

Put the info in and you will see what adds up immediately.

Hmm, yes indeed... Let's keep thinking ))))
 
I understand this is a test in the tester....
 
Vitalie Postolache:
Hmm, yes indeed... Let's keep thinking ))))

I also thought it was counting as it should.
I should not have put this info in the code and life would have been easier))

And now it's baffling how the function didn't work properly all this time!!!