TesterStatistics(STAT_GROSS_PROFIT) return incorrect value during of the testing an EA

 

hey guys


i write this code to stop continue of testing an EA in optimization procedure.


when i debug it line by line i understand that "dd" is correctly calculated,
but both of "pt" and "ls" is 0.0 although i have some positions which close with profit or loss.


how can i calculate "GROSS_PROFIT" or "GROSS_LOSS" during of the testing procedure of an EA ???

thnx

best regards


void OnTick()
   {
    ...
    if(testerNotSatisfy())
       {
        is_Loss = true;
        ExpertRemove();
        TesterStop();
       }
    ...
   }

double OnTester(void)
   {
    if(is_Loss)
        return 0;
    return AccountInfoDouble(ACCOUNT_BALANCE);
   }

//--- testerNot Satisfy
bool testerNotSatisfy()
   {
    static double prev_mon_loss_usd = 0;
    static datetime start_test_date = datetime(0);

    if(start_test_date == datetime(0))
        start_test_date = TimeCurrent();

    double dd = TesterStatistics(STAT_EQUITY_DD);
    double fb = TesterStatistics(STAT_INITIAL_DEPOSIT);
    double pt = TesterStatistics(STAT_GROSS_PROFIT);
    double ls = TesterStatistics(STAT_GROSS_LOSS);

    if(dd
       > InpT_Max_DD_Perc_Of_Init_Balance / 100 * fb)
        return true;

    if(pt != 0
       && ls / pt > InpT_Max_Gross_Loss_Gross_Profit_Ratio_Perc)
        return true;

    MqlDateTime diff;
    TimeToStruct(TimeCurrent() - start_test_date, diff);

    if(diff.mon > 1)
       {
        start_test_date = TimeCurrent();
        prev_mon_loss_usd = ls;
       }

    if(ls - prev_mon_loss_usd
       > InpT_Max_Monthly_Loss_Perc_Of_Init_Balance / 100 * fb)
        return true;

    return false;
   }