CDealInfo does not work in the strategy tester?

 

I am doing the following (the code below) but I only see zeros whith "Comment output". I don't know if it is because "CDealInfo" does not work in test mode, or i'm doing somthing wrong.

Can someone tell me please?

Thank you!!



CDealInfo dealInfo; 

//+------------------------------------------------------------------+
   void Calculate(int pMagicNumber)
   {
      totalProfit = 0;
      deals = 0; 
      average = 0;     
      
      double partialProfit[];
      ArrayResize(partialProfit,PositionsTotal()-1,0);    

      
      for(int i=0; i<=PositionsTotal()-1; i++)
      {
         if(dealInfo.SelectByIndex(i))
         {
            if(dealInfo.Magic()!=pMagicNumber)continue;           

             partialProfit[deals] = dealInfo.Commission() + dealInfo.Swap() + dealInfo.Profit();             
             totalProfit += partialProfit[deals];
             deals++;            
         }
      }
      
      if(deals==0) return;
      
      average = totalProfit/deals;
      
      standarDeviation = GetStandarDeviation(partialProfit);    
      
      confidenceIntervalUpper  =  average + standarDeviation;
      confidenceIntervalLower  =  average - standarDeviation;     

      ArrayFree(partialProfit);     
        
   }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{

               profitStatistics.Calculate(4123);
               Comment(
                     " \ndeals=", profitStatistics.deals,            
                     " \ntotalProfit=", profitStatistics.totalProfit, 
                     " \naverage=", profitStatistics.average,
                     " \nCIU=", profitStatistics.confidenceIntervalUpper,
                     " \nCIL=", profitStatistics.confidenceIntervalLower
                   );  
         
}

 

You mixed horses and people into one pile :)

Describe your task - explain what exactly do you want to do?

 
profitStatistics.Calculate() and Calculate() seem to be two different functions.

Also, it is not clear how the object profitStatistics is getting the values.

More code is involved than you have posted, obviously.

Somewhere outside of the posted code is the error, as it seems.




 
Vladimir Karputov:

You mixed horses and people into one pile :)

Describe your task - explain what exactly do you want to do?

I only want to calculate the average and the standard deviation of the profits of my EA ... (I will post the complete class)

 
karp wak :

I only want to calculate the average and the standard deviation of the profits of my EA ... (I will post the complete class)

You don't need the complete code at this stage.

How do you want to calculate the parameters? What is needed for this - to refer to the trade history for each position?

 
Dominik Egert:
profitStatistics.Calculate() and Calculate() seem to be two different functions.

Also, it is not clear how the object profitStatistics is getting the values.

More code is involved than you have posted, obviously.

Somewhere outside of the posted code is the error, as it seems.




This is the complete code:



#include <Trade\DealInfo.mqh>
//+------------------------------------------------------------------+
#ifndef PROFITSTATICS_MQH 
#define PROFITSTATICS_MQH 
//+------------------------------------------------------------------+
class ProfitStatistics
{
   
   CDealInfo dealInfo;   

public:
   int deals;              
   double average;         
   double standarDeviation;
   double totalProfit;     
   
   double confidenceIntervalUpper;
   double confidenceIntervalLower;

public:
   //+------------------------------------------------------------------+
   void ProfitStatistics()
   {
      totalProfit = 0.0;
      average = 0;
      deals = 0;
   } 
   //+------------------------------------------------------------------+
   ~ProfitStatistics()
   {   
   }
   //+------------------------------------------------------------------+
   void Calculate(int pMagicNumber)
   {
      totalProfit = 0;
      deals = 0; 
      average = 0;     
      
      double partialProfit[];
      ArrayResize(partialProfit,PositionsTotal()-1,0); 

      
      for(int i=0; i<=PositionsTotal()-1; i++)
      {
         if(dealInfo.SelectByIndex(i))
         {
            if(dealInfo.Magic()!=pMagicNumber)continue;           

             partialProfit[deals] = dealInfo.Commission() + dealInfo.Swap() + dealInfo.Profit();             
             totalProfit += partialProfit[deals];
             deals++;            
         }
      }
      
      if(deals!=0)
      {      
         average = totalProfit/deals;
         
         standarDeviation = GetStandarDeviation(partialProfit);    
         
         confidenceIntervalUpper  =  average + standarDeviation;
         confidenceIntervalLower  =  average + standarDeviation;     
      }

      ArrayFree(partialProfit);
      
      
   }
   //+------------------------------------------------------------------+
   private:
   double GetStandarDeviation(double &partialProfit[])
   {      
      double variance=0;
      
      for(int i=0; i<deals; i++)      
         variance += (partialProfit[i] - average)*(partialProfit[i] - average);
            
      variance /= deals;
      
      return sqrt(variance);      
   }   

};
//+------------------------------------------------------------------+
#endif


//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{   
   
      profitStatistics.Calculate(EXPERT_MAGIC);
         
      Comment(
               " \ndeals=",       profitStatistics.deals,           
               " \ntotalProfit=", profitStatistics.totalProfit,       
               " \naverage=",     profitStatistics.average,
               " \nCIU=",         profitStatistics.confidenceIntervalUpper,
               " \nCIL=",         profitStatistics.confidenceIntervalLower
             );  
}
//+--





 

I still don't understand - what exactly do you want to do?

The main misunderstanding is why try to cross a knight and a bishop:

      for(int i=0; i<=PositionsTotal()-1; i++)
      {
         if(dealInfo.SelectByIndex(i))
         {
            if(dealInfo.Magic()!=pMagicNumber)continue;           

             partialProfit[deals] = dealInfo.Commission() + dealInfo.Swap() + dealInfo.Profit();             
             totalProfit += partialProfit[deals];
             deals++;            
         }
      }
 
Vladimir Karputov:

I still don't understand - what exactly do you want to do?

The main misunderstanding is why try to cross a knight and a bishop:

It is not like that? I want the average of the positions that have already been closed .... How to do it correctly?

 
Vladimir Karputov:

I still don't understand - what exactly do you want to do?

The main misunderstanding is why try to cross a knight and a bishop:

Ok i changed PositionsTotal() by HistoryDealsTotal()... but it still not working :-(

 
karp wak :

It is not like that? I want the average of the positions that have already been closed .... How to do it correctly?

Flies - separately, cutlets - separately.

If you want information on POSITIONS - work WITH POSITIONS:

***
#include <Trade\PositionInfo.mqh>
#include <Trade\SymbolInfo.mqh>
//---
CPositionInfo  m_position;                   // object of CPositionInfo class
CSymbolInfo    m_symbol;                     // object of CSymbolInfo class
***
//+------------------------------------------------------------------+
//| Profit all positions                                             |
//+------------------------------------------------------------------+
double ProfitAllPositions(void)
  {
   double profit=0.0;
   for(int i=PositionsTotal()-1; i>=0; i--)
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
         if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==InpMagic)
            profit+=m_position.Commission()+m_position.Swap()+m_position.Profit();
//---
   return(profit);
  }
 
Vladimir Karputov:

Flies - separately, cutlets - separately.

If you want information on POSITIONS - work WITH POSITIONS:

Thank you so much Vladimir!! :-)