CTradeStatistics - MetaTrader 5 Library | Trading Script Download - MT4/MT5 Resources
The CTradeStatistics class contains all ENUM_STATISTICS enum parameter calculations.
All parameters in this class (except equity drawdown) can be calculated based on trading history.
The main purpose of this class is to remove the teststatistics() functional limitations, i.e. to be able to obtain the necessary statistics at any time during the test and outside the strategy tester.
Example for use outside the tester
All parameters are calculated by calling the CTradeStatistics::Calculate() function. After the function executes successfully, the results can be obtained by calling numerous methods with names similar to those of the statistical parameters.
CTradeStatistics m_stat; if (m_stat.calculate()) print format ( "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 using this class can be found in the TradeStatistics.mq5 script.
This Trade Statistics Panel is designed for better visualization of the results.
Example used in tester
To correctly calculate equity drawdown, the CTradeStatistics::CalculateEquityDD() function should be used.
#includeCTradeStatistics m_stat; //+----------------------------------------------------------------------------------+ //|Expert initialization function | //+------------------------------------------------------------------+ Integer initialization () { m_stat.CalculateEquityDD(CALC_INIT); return ( 0 ); } //+------------------------------------------------------------------+ //|Expert to initialize function | //+------------------------------------------------------------------+ Blank solution initialization ( constant integer reason) { m_stat.CalculateEquityDD(CALC_DEINIT); if (m_stat.Calculate())m_stat.PrintStatistics(); } //+------------------------------------------------------------------+ //|Expert check function | //+------------------------------------------------------------------+ Blank check () { m_stat.CalculateEquityDD(CALC_TICK); }
It should be noted that reliable values for statistical indicators can be obtained at any point in the program, not just at the end of the test using the OnTester() or OnDeinit() events. The calculation can be done using the update () event as shown in the following example:
Attachment download
📎 tradestatistics.mq5 (1.6 KB)
📎 ctradestatistics.mqh (37.73 KB)
Source: MQL5 #1081
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •