TesterStatistics

이 함수는 검사 결과를 기반으로 계산된 지정된 통계 매개변수의 값을 반환.

double  TesterStatistics(
   ENUM_STATISTICS statistic_id      // ID
   );

매개변수

statistic_id

[in]   ENUM_STATISTICS 열거에서 가져온 통계 매개변수의 ID.

값 반환

검사 결과의 통계 매개변수 값.

주의

이 기능은 테스터의 OnTester() 또는 OnDeinit() 내에서 호출할 수 있습니다. 다른 경우에는 결과가 정의되지 않습니다.

예:

// 표준 "MACD Sample.mq5" 파일을 기반으로 한 EA
// Tester 이벤트 핸들러에서 TesterStatistics()의 결과를 표시합니다.
#define MACD_MAGIC 1234502
//---
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\AccountInfo.mqh>
//---
input double InpLots          =0.1// 랏
input int    InpTakeProfit    =50;  // 수익(핍)
input int    InpTrailingStop  =30;  // 트레일링 스탑 레벨(핍)
input int    InpMACDOpenLevel =3;   // MACD 오픈 레벨(핍)
input int    InpMACDCloseLevel=2;   // MACD 클로즈 레벨(핍)
input int    InpMATrendPeriod =26;  // MA 트렌드 기간
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit(void)
  {
//--- 필요한 모든 객체를 생성합니다.
   if(!ExtExpert.Init())
      return(INIT_FAILED);
//--- 초기화 성공
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert new tick handling function                                |
//+------------------------------------------------------------------+
void OnTick(void)
  {
   static datetime limit_time=0// 'timeout'을 고려한 마지막 호출 시간
//--- if the time exceeds the specified limit_time value
   if(TimeCurrent()>=limit_time)
     {
      //--- 데이터 확인
      if(Bars(Symbol(),Period())>2*InpMATrendPeriod)
        {
         //--- 성공하면 Limit_time을 'timeout'초만큼 늘립니다.
         if(ExtExpert.Processing())
            limit_time=TimeCurrent()+ExtTimeOut;
        }
     }
  }
//+------------------------------------------------------------------+
//| Expert tester handling function                                  |
//+------------------------------------------------------------------+
double OnTester(void)
  {
   double ret=TesterStatistics(STAT_PROFIT_FACTOR);
   double profit=TesterStatistics(STAT_PROFIT);
   int    trades_total=(int)TesterStatistics(STAT_TRADES);
   int    profit_total=(int)TesterStatistics(STAT_PROFIT_TRADES);
   int    loss_total=(int)TesterStatistics(STAT_LOSS_TRADES);
   PrintFormat("%s: Profit = %.2f, trades total: %lu, profit trades total: %lu, loss trades total: %lu, profit factor: %.2f",__FUNCTION__,profit,trades_total,profit_total,loss_total,ret);
   return(ret);
   /*
   Result:
   OnTesterProfit = 209.84trades total13profit trades total11loss trades total2profit factor3.02
   final balance 10209.84 USD
   OnTester result 3.020606644198363
   */
  }