거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Facebook에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

CTradeStatistics - MetaTrader 5용 라이브러리

조회수:
8520
평가:
(48)
게시됨:
2012.11.15 12:14
업데이트됨:
2014.02.03 09:06
\MQL5\Scripts\ \MQL5\Include\
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

The CTradeStatistics class contains all ENUM_STATISTICS enumeration parameter calculations.

All parameters, except for equity drawdown, can in this class be calculated based on the trade history.

The main purpose of the class is to remove the TesterStatistics() function restriction, i.e. to be able to get the necessary statistical data at any time during testing, as well as outside of the strategy tester.

An example of using outside of the tester

All parameters are calculated by calling the CTradeStatistics::Calculate() function. After the successful execution of this function, the results are available through the calls of numerous methods, their names being similar to the names of statistical parameters. 

Code example:

CTradeStatistics m_stat;

if(m_stat.Calculate()) PrintFormat("LR Correlation: %.2f",m_stat.LRCorrelation());
else Print(m_stat.GetLastErrorString());

Result:

2012.09.13 08:52:19 TradeStatistics (EURUSD,H1) LR Correlation: 0.97

 

The CTradeStatistics::PrintStatistics() function can be used to print all parameters to the log.

if(m_stat.Calculate()) PrintStatistics();

A simple example of working with the class can be found in the TradeStatistics.mq5 script.

The TradeStatisticsPanel panel is designed for better visualization of results. 

An example of using in the tester

To correctly calculate equity drawdown, the CTradeStatistics::CalculateEquityDD() function should be used.

Code example:

#include <CTradeStatistics.mqh>
CTradeStatistics m_stat;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   m_stat.CalculateEquityDD(CALC_INIT);

   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   m_stat.CalculateEquityDD(CALC_DEINIT);

   if(m_stat.Calculate())m_stat.PrintStatistics();

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   m_stat.CalculateEquityDD(CALC_TICK);

  }

It should be noted that reliable values of statistical indicators can be obtained at any point in the program and not only at the end of testing using the OnTester() or OnDeinit() events. Calculations can be updated using the OnTrade() event as shown in the following example:

void OnTrade()
  {
//--- block repeated requests at same sec.
   static datetime time_on_trade;
   if(time_on_trade==TimeTradeServer())return;
   time_on_trade=TimeTradeServer();

//--- update statistics
   if(!m_stat.Calculate())Print(m_stat.GetLastErrorString());

  }

MetaQuotes Ltd에서 러시아어로 번역함.
원본 코드: https://www.mql5.com/ru/code/1081

BidAskChannel BidAskChannel

The BidAskChannel indicator is designed to account for spread in the shadows of candles.

Squize_MA Squize_MA

The Squize_MA indicator displays the intersection of two Moving Averages with different averaging periods. The chart also features conventional flat limits.

TradeStatisticsPanel TradeStatisticsPanel

The panel for the display of statistical parameters calculated based on the trade history.

CSelectFile CSelectFile

The file selection graphical interface class.