Cálculo de beneficios de las órdenes cerradas "AYUDA" - página 2

 
Renat Akhtyamov:

No, no me refiero a lo que ya has escrito.
Dígame en palabras - cálculo de beneficios para las órdenes cerradas que le interesan
- diario
- con pérdidas
- último pedido
¿o algo más?
Describa la serie

Una serie de últimos pedidos cerrados "por ahora"

 
Natashe4ka:

Serie de últimos pedidos cerrados "por ahora"

Es decir, necesita información sobre la serie de órdenes cerradas más recientemente, si lo he entendido bien.

Para aplicar este enfoque, primero debe rellenar la matriz de tickets de pedido en cada cierre exitoso y luego extraer la información de los pedidos cerrados en la forma que necesite

¿Puede hacerlo usted mismo?

 

Prueba con


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:

Prueba con


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

¿Y si no se cierra al mismo tiempo?

No es del todo correcto.

Y si se acuerda de ello al presentar la orden de cierre, entonces estará bien.

pero esta línea...

t=OrderCloseTime();

no es necesario.

Sacará el total de toda la serie

Pero la señora quiere información más detallada, según entendí en el primer post

 
Renat Akhtyamov:
¿Y si no se cierra al mismo tiempo?
Si la función se cierra, todo funcionará
 
Renat Akhtyamov:

Así que necesita información sobre la última serie de órdenes cerradas, si lo he entendido bien.

Para poner en práctica este enfoque, primero debe crear una matriz de tickets de órdenes al cierre exitoso y luego extraer la información de las órdenes cerradas

¿Puede hacerlo usted mismo?

Por favor, aconséjenos usar un ejemplo.

Es decir

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

¿Y luego comparar?

 
Natashe4ka:

Será mejor que me des un ejemplo.

Es decir

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

¿Y luego comparar?

No hay problema.

Ahora lo único que queda por aclarar es cómo debe ser la información de las órdenes cerradas de la serie ?

¿Se trata de una transferencia o hay que dividir el importe entre + y -?

 

Existe un indicador para

i-Profit

Produce losbeneficios actuales de hoy, de la semana, del mes y del año.

 
Natashe4ka:

Un ejemplo mejor sería

He aquí un ejemplo:

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

El resto de la historia

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


Lo conseguimos incluso si reiniciamos el terminal

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

Existe un indicador para

i-Profit

Produce losbeneficios actuales de hoy, de la semana, del mes y del año.

No es adecuado, no hay información para 10 años.
Razón de la queja: