update
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#include <Trade/Trade.mqh>
|
||||
|
||||
enum CUSTOM_MAX_TYPE {
|
||||
CM_WIN_LOSS_RATIO,
|
||||
CM_WIN_PERCENT
|
||||
};
|
||||
|
||||
class CustomMax : public CObject {
|
||||
protected:
|
||||
double custom_criteria;
|
||||
|
||||
double win_loss_ratio(int min_required_trades);
|
||||
double win_percent_min_trades(int min_required_trades);
|
||||
|
||||
public:
|
||||
double calculate_custom_criteria(CUSTOM_MAX_TYPE cm_type, int min_trades = 0);
|
||||
};
|
||||
|
||||
double CustomMax::calculate_custom_criteria(CUSTOM_MAX_TYPE cm_type, int min_trades) {
|
||||
switch(cm_type) {
|
||||
case CM_WIN_LOSS_RATIO:
|
||||
custom_criteria = win_loss_ratio(min_trades);
|
||||
break;
|
||||
case CM_WIN_PERCENT:
|
||||
custom_criteria = win_percent_min_trades(min_trades);
|
||||
break;
|
||||
default:
|
||||
custom_criteria = 0;
|
||||
break;
|
||||
}
|
||||
return custom_criteria;
|
||||
}
|
||||
|
||||
// Returns the win/loss ratio, with min trades check
|
||||
double CustomMax::win_loss_ratio(int min_required_trades) {
|
||||
double wins = TesterStatistics(STAT_PROFIT_TRADES);
|
||||
double losses = TesterStatistics(STAT_LOSS_TRADES);
|
||||
double total_trades = TesterStatistics(STAT_TRADES);
|
||||
if((min_required_trades > 0 && total_trades < min_required_trades) || total_trades == 0) return 0;
|
||||
if(losses == 0) return 0; // Prevent division by zero
|
||||
return wins / losses;
|
||||
}
|
||||
|
||||
// Returns the win percentage, with min trades check
|
||||
double CustomMax::win_percent_min_trades(int min_required_trades) {
|
||||
double wins = TesterStatistics(STAT_PROFIT_TRADES);
|
||||
double total_trades = TesterStatistics(STAT_TRADES);
|
||||
if((min_required_trades > 0 && total_trades < min_required_trades) || total_trades == 0) return 0;
|
||||
double result = wins / total_trades * 100;
|
||||
if(!MathIsValidNumber(result)) return 0;
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
enum MODE_SPLIT_DATA{
|
||||
NO_SPLIT,
|
||||
ODD_YEARS,
|
||||
EVEN_YEARS,
|
||||
ODD_MONTHS,
|
||||
EVEN_MONTHS,
|
||||
ODD_WEEKS,
|
||||
EVEN_WEEKS
|
||||
};
|
||||
|
||||
class TestDataSplit {
|
||||
public:
|
||||
bool in_test_period(MODE_SPLIT_DATA data_split_method);
|
||||
};
|
||||
|
||||
bool TestDataSplit::in_test_period(MODE_SPLIT_DATA data_split_method) {
|
||||
string result[];
|
||||
string string_tc = TimeToString(TimeCurrent());
|
||||
|
||||
// Extract components from datetime string (assumes YYYY.MM.DD format)
|
||||
ushort u_sep = StringGetCharacter(".", 0);
|
||||
StringSplit(string_tc, u_sep, result);
|
||||
|
||||
bool odd_year = int(result[0]) % 2;
|
||||
bool odd_month = int(result[1]) % 2;
|
||||
|
||||
// Calculate week of the year (basic approximation)
|
||||
MqlDateTime dt;
|
||||
TimeToStruct(TimeCurrent(), dt);
|
||||
int iDay = (dt.day_of_week + 6) % 7 + 1; // Convert to 1=Mon,...,7=Sun
|
||||
int iWeek = (dt.day_of_year - iDay + 10) / 7; // Estimate ISO week number
|
||||
bool odd_week = iWeek % 2;
|
||||
|
||||
// Split logic depending on mode
|
||||
if (data_split_method == NO_SPLIT)
|
||||
return true;
|
||||
if (data_split_method == ODD_YEARS && odd_year)
|
||||
return true;
|
||||
if (data_split_method == EVEN_YEARS && !odd_year)
|
||||
return true;
|
||||
if (data_split_method == ODD_MONTHS && odd_month)
|
||||
return true;
|
||||
if (data_split_method == EVEN_MONTHS && !odd_month)
|
||||
return true;
|
||||
if (data_split_method == ODD_WEEKS && odd_week)
|
||||
return true;
|
||||
if (data_split_method == EVEN_WEEKS && !odd_week)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user