Good afternoon!
I am interested in whether it is possible to put LR Correlation in the OnTester() function, in order to optimise the Expert Advisor by this criterion, via Custom max?
The description gives an example with OnTrade(). Nothing prevents you from transferring the calculations to OnTester().
I am not very familiar with mql5, so please excuse any obvious mistakes.
I try to do this in the EA code before OnDeinit:
double OnTester() { double lrk=TesterStatistics(STAT_LR_CORRELATION); return(lrk); }
The error "'STAT_LR_CORRELATION' - can't convert enum" comes out.
If so:
double OnTester() { //--- 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()); }
Errors: "'return' - function must return a value", " '}' - not all control paths return a value".
1 and 2 line in the EA:
#include <CTradeStatistics.mqh>
CTradeStatistics m_stat;Tell me what is wrong?
I did it by trial and error:
double OnTester() { CTradeStatistics m_stat; if(m_stat.Calculate()) PrintFormat("LR Correlation: %.2f",m_stat.LRCorrelation()); else Print(m_stat.GetLastErrorString()); double LRC=(double)m_stat.LRCorrelation(); return(LRC); }I think it worked...?
Andrei, there are some comments.
1. line 500
if(m_balance_data.At(i)!=0.0) fix it to if(m_balance_data.At(i-1)!=0.0)
2. Line 511
no check of denominator m_initial_deposit to 0
3. be sure to specify that you are using the m_sharpe_ratio calculation for the Annual Sharpe Ratio option with the RiskFreeRate option
as this is only one of the options and it is specifically different from the standard one.
I found this code can't calculate any statistics related to equity drawdown. Anyone has a success to calculate equity drawdown with their own code ???
What do you mean? I must be misunderstanding your question because this simple answer can't possibly be what you are looking for is it? ---> Equity - Balance = { draw-down if negative, profit if positive } pretty simple calculation. with MT5 trade classes you can create an account object CAccountInfo acc; acc is the created account info object giving you quick access to all account detail functions. then do this acc.Equity()-acc.Balance(). Well to be honest you can use an even simpler code acc.Profit(). If positive is profit, if negative is draw-down right? Negative equity profit is the same as draw-down. Profit() is the difference between equity and balance
If your question is more complex please add details ;)
perfect work!
if you want to avoid to get compile warnings
you need to add null element to enum deal_result:
//+------------------------------------------------------------------+
//| deal result |
//+------------------------------------------------------------------+
enum deal_result
{
NOVALUE=0, //<---- added
WIN=1,
LOSS
};
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
CTradeStatistics:
Author: Andrey Voytenko