Profit calculation of closed orders "HELP" - page 2

 
Renat Akhtyamov:

No, I don't mean what you have already written.
Tell me in words - profit calculation for which closed orders you are interested in
- daily
- loss-making
- last order
or something else?
Describe the series

A series of last closed orders "for now"

 
Natashe4ka:

Series of last closed orders "for now"

That is, you need information about the most recently closed series of orders, if I understand it correctly?

To implement this approach, you should first fill the array of order tickets at each successful closing and then pull out the information on closed orders in the form you need

Can you do it yourself?

 

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);
}
 
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);
}

What if it doesn't close at the same time?

Not quite right.

And if you remember t when submitting the closing order, then it will be fine.

but this line...

t=OrderCloseTime();

is not necessary.

It will pull the total for the entire series

But madam wants more detailed information, as I understood from the first post

 
Renat Akhtyamov:
What if it doesn't close at the same time?
If there is a function to close, it will all work out
 
Renat Akhtyamov:

So you need information on the last closed series of orders, if I understand correctly?

To implement this approach, you should first create an array of order tickets at successful closing and then pull information on closed orders

Can you do it yourself?

Please advise us to use an example.

I.e.

if (cnt>0) Ticket=OrderTicket()-1;

And then compare ?

 
Natashe4ka:

You' d better give me an example.

I.e.

if (cnt>0) Ticket=OrderTicket()-1;

And then compare ?

No problem.

Now the only thing left to clarify is how the information on the closed orders of the series should look like ?

Is it a transfer or should the amount be divided by + and - ?

 

There is an indicator for

i-Profit

Outputscurrent profits for today, week, month, year.

 
Natashe4ka:

A better example would be

Here is an example:

int ClosePosition(int type=-1,int mg=-1) {
GlobalVariableSet(GetGlobalVariableName("LastProfit"), TimeCurrent()); // запомним время закрытия
// здесь код закрытия всех и сразу, нужен цикл, чтоб не выходил с функции до полного закрытия всех
}

The rest of the story

//+----------------------------------------------------------------------------+
//|    Возвращает суммарный профит в валюте депозита серии закрытых позиций    |
//+----------------------------------------------------------------------------+
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);
}

//===============================================================================================
//----------------------- Создает и возвращает имя глобальной переменной -----------------------+
//===============================================================================================
string GetGlobalVariableName(string name="", string symb="0") {
if(symb=="0") { symb=Symbol();}
  if(!MQLInfoInteger(MQL_TESTER)) {
   return(prefix+symb+"_"+(string)AccountInfoInteger(ACCOUNT_LOGIN)+"_"+MQLInfoString(MQL_PROGRAM_NAME)+"_"+name);
  } else {
   return(prefix+symb+"_"+(string)AccountInfoInteger(ACCOUNT_LOGIN)+"_"+MQLInfoString(MQL_PROGRAM_NAME)+"_tester"+"_"+name);
}}


We get it even if we restart the terminal

void OnTick()
{
   Comment( LastProfitCL(-1, (datetime)GlobalVariableGet(GetGlobalVariableName("LastProfit"))) );
}
 
Alekseu Fedotov:

There is an indicator for

i-Profit

Outputscurrent profits for today, week, month, year.

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