Download MetaTrader 5

How to get profit by EA?

To add comments, please log in or register
RodrigoMT5
50
RodrigoMT5  

If I remove conditionals at line 1 and 2, it works fine getting the profit about time that I want, the problem is that i want to get only a specific  EA profit. Doing this bellow i receive 4755 error(trade deal not found). Why it does not work? 

double getResultadoDiarioEA(){
   double retorno = 0;
   datetime dataInicial = getDataInicioPregaoAtual();
   datetime dataFinal=TimeCurrent();
   
   HistorySelect(dataInicial, dataFinal);
   uint total=HistoryDealsTotal();
   ulong ticket=0;
   for(uint i=0; i < total; i++){
      ticket = HistoryDealGetTicket(i);
      if (HistoryDealSelect(ticket)){      //1
         if (HistoryDealGetInteger(ticket, DEAL_MAGIC) == meuMagic){              //2
            retorno = retorno + HistoryDealGetDouble(ticket, DEAL_PROFIT);
         }
      } else {
          Print ("Erro encontrado ==> " + GetLastError());
      }
   }
   return retorno;
}

Trinh Dat
40255
Trinh Dat  
double getResultadoDiarioEA(){
   double retorno = 0;
   datetime dataInicial = getDataInicioPregaoAtual();
   datetime dataFinal=TimeCurrent();
   
   HistorySelect(dataInicial, dataFinal);
   uint total=HistoryDealsTotal();
   ulong ticket=0;
   for(uint i=0; i < total; i++){
      ticket = HistoryDealGetTicket(i);
         if (HistoryDealGetInteger(ticket, DEAL_MAGIC) == meuMagic){              //2
            retorno = retorno + HistoryDealGetDouble(ticket, DEAL_PROFIT);
         }
   }
   return retorno;
}
RodrigoMT5
50
RodrigoMT5  
Trinh Dat:
i tried it but didnt work as well. there is no error but always return zero.
Tan Phan Ngoc
1327
Tan Phan Ngoc  
Never EA get profit so long.
Roberto Jacobs
49158
Roberto Jacobs  
RodrigoMT5:

If I remove conditionals at line 1 and 2, it works fine getting the profit about time that I want, the problem is that i want to get only a specific  EA profit. Doing this bellow i receive 4755 error(trade deal not found). Why it does not work? 

double getResultadoDiarioEA(){
   double retorno = 0;
   datetime dataInicial = getDataInicioPregaoAtual();
   datetime dataFinal=TimeCurrent();
   
   HistorySelect(dataInicial, dataFinal);
   uint total=HistoryDealsTotal();
   ulong ticket=0;
   for(uint i=0; i < total; i++){
      ticket = HistoryDealGetTicket(i);
      if (HistoryDealSelect(ticket)){      //1
         if (HistoryDealGetInteger(ticket, DEAL_MAGIC) == meuMagic){              //2
            retorno = retorno + HistoryDealGetDouble(ticket, DEAL_PROFIT);
         }
      } else {
          Print ("Erro encontrado ==> " + GetLastError());
      }
   }
   return retorno;
}

//probably should have

return(retorno);
RodrigoMT5
50
RodrigoMT5  
3rjfx:
3rjfx, unfortunately there is no syntax problem because if i remove conditionals at line 1 and 2, it works fine returning all my profit for the this period. My idea is to get a profit only for a specific EA and magic number was supposed for solve this, I don´t understand why its so hard.  
Alain Verleyen
Moderator
35063
Alain Verleyen  
RodrigoMT5:
3rjfx, unfortunately there is no syntax problem because if i remove conditionals at line 1 and 2, it works fine returning all my profit for the this period. My idea is to get a profit only for a specific EA and magic number was supposed for solve this, I don´t understand why its so hard.  
You have to debug your code. What are the dates ? How many deals are selected ?
RodrigoMT5
50
RodrigoMT5  
Alain Verleyen:
You have to debug your code. What are the dates ? How many deals are selected ?

Alain,

dates are fine because without conditionals I get the right value of all my profit for this period. The problem is about getting some information about the deal. I debugged and could check that my deal has no magic number, but I use magic in every order that I send. What I want to know is why mt5 does not save my magic.  

Alain Verleyen
Moderator
35063
Alain Verleyen  
RodrigoMT5:

Alain,

dates are fine because without conditionals I get the right value of all my profit for this period. The problem is about getting some information about the deal. I debugged and could check that my deal has no magic number, but I use magic in every order that I send. What I want to know is why mt5 does not save my magic.  

How are closed your positions, by SL/TP ?
RodrigoMT5
50
RodrigoMT5  
Alain Verleyen:
How are closed your positions, by SL/TP ?
yes, sl or tp.
Alain Verleyen
Moderator
35063
Alain Verleyen  
RodrigoMT5:
yes, sl or tp.
This is done by the server, not your EA, then these deals don't have a magic number.
To add comments, please log in or register