MqlCIByLeo/Src/BacktestResults/Base.mqh

128 lines
5.6 KiB
MQL5
Raw Permalink Normal View History

2026-04-11 12:11:56 -05:00
//+------------------------------------------------------------------+
//| Base.mqh |
//| Copyright 2026,Niquel Mendoza. |
//| https://www.mql5.com/en/users/nique_372 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026,Niquel Mendoza."
#property link "https://www.mql5.com/en/users/nique_372"
#property strict
#ifndef MQLCYBYLEO_SRC_BACKTESTER_RESULTS_BASE_MQH
#define MQLCYBYLEO_SRC_BACKTESTER_RESULTS_BASE_MQH
//+------------------------------------------------------------------+
//| Estrucutra base |
//+------------------------------------------------------------------+
struct pack(8) BackRes
{
double initial_deposit;
double withdrawal;
double profit;
double gross_profit;
double gross_loss;
double max_profit_trade;
double max_loss_trade;
double con_profit_max;
double max_con_wins;
double con_loss_max;
double max_con_losses;
double balance_min;
double balance_dd;
double balance_dd_pct;
double balance_ddrel_pct;
double balance_dd_relative;
double equity_min;
double equity_dd;
double equity_dd_pct;
double equity_ddrel_pct;
double equity_dd_relative;
double expected_payoff;
double profit_factor;
double recovery_factor;
double sharpe_ratio;
double min_margin_level;
double custom_ontester;
int con_profit_max_trades;
int max_con_profit_trades;
int con_loss_max_trades;
int max_con_loss_trades;
int deals;
int trades;
int profit_trades;
int loss_trades;
int short_trades;
int long_trades;
int profit_short_trades;
int profit_long_trades;
int profit_trades_avgcon;
int loss_trades_avgcon;
//---
bool Save(const string& path, bool comon_flag)
{
const int fh = ::FileOpen(path, FILE_WRITE | FILE_BIN | (comon_flag ? FILE_COMMON : 0));
if(fh == INVALID_HANDLE)
return false;
::FileWriteStruct(fh, this);
::FileClose(fh);
return true;
}
//---
bool Load(const string& path, bool comon_flag)
{
const int fh = ::FileOpen(path, FILE_READ | FILE_BIN | (comon_flag ? FILE_COMMON : 0));
if(fh == INVALID_HANDLE)
return false;
::FileReadStruct(fh, this);
::FileClose(fh);
return true;
}
//---
void Collect()
{
initial_deposit = ::TesterStatistics(STAT_INITIAL_DEPOSIT);
withdrawal = ::TesterStatistics(STAT_WITHDRAWAL);
profit = ::TesterStatistics(STAT_PROFIT);
gross_profit = ::TesterStatistics(STAT_GROSS_PROFIT);
gross_loss = ::TesterStatistics(STAT_GROSS_LOSS);
max_profit_trade = ::TesterStatistics(STAT_MAX_PROFITTRADE);
max_loss_trade = ::TesterStatistics(STAT_MAX_LOSSTRADE);
con_profit_max = ::TesterStatistics(STAT_CONPROFITMAX);
con_profit_max_trades = (int)::TesterStatistics(STAT_CONPROFITMAX_TRADES);
max_con_wins = ::TesterStatistics(STAT_MAX_CONWINS);
max_con_profit_trades = (int)::TesterStatistics(STAT_MAX_CONPROFIT_TRADES);
con_loss_max = ::TesterStatistics(STAT_CONLOSSMAX);
con_loss_max_trades = (int)::TesterStatistics(STAT_CONLOSSMAX_TRADES);
max_con_losses = ::TesterStatistics(STAT_MAX_CONLOSSES);
max_con_loss_trades = (int)::TesterStatistics(STAT_MAX_CONLOSS_TRADES);
balance_min = ::TesterStatistics(STAT_BALANCEMIN);
balance_dd = ::TesterStatistics(STAT_BALANCE_DD);
balance_dd_pct = ::TesterStatistics(STAT_BALANCEDD_PERCENT);
balance_ddrel_pct = ::TesterStatistics(STAT_BALANCE_DDREL_PERCENT);
balance_dd_relative = ::TesterStatistics(STAT_BALANCE_DD_RELATIVE);
equity_min = ::TesterStatistics(STAT_EQUITYMIN);
equity_dd = ::TesterStatistics(STAT_EQUITY_DD);
equity_dd_pct = ::TesterStatistics(STAT_EQUITYDD_PERCENT);
equity_ddrel_pct = ::TesterStatistics(STAT_EQUITY_DDREL_PERCENT);
equity_dd_relative = ::TesterStatistics(STAT_EQUITY_DD_RELATIVE);
expected_payoff = ::TesterStatistics(STAT_EXPECTED_PAYOFF);
profit_factor = ::TesterStatistics(STAT_PROFIT_FACTOR);
recovery_factor = ::TesterStatistics(STAT_RECOVERY_FACTOR);
sharpe_ratio = ::TesterStatistics(STAT_SHARPE_RATIO);
min_margin_level = ::TesterStatistics(STAT_MIN_MARGINLEVEL);
custom_ontester = ::TesterStatistics(STAT_CUSTOM_ONTESTER);
deals = (int)::TesterStatistics(STAT_DEALS);
trades = (int)::TesterStatistics(STAT_TRADES);
profit_trades = (int)::TesterStatistics(STAT_PROFIT_TRADES);
loss_trades = (int)::TesterStatistics(STAT_LOSS_TRADES);
short_trades = (int)::TesterStatistics(STAT_SHORT_TRADES);
long_trades = (int)::TesterStatistics(STAT_LONG_TRADES);
profit_short_trades = (int)::TesterStatistics(STAT_PROFIT_SHORTTRADES);
profit_long_trades = (int)::TesterStatistics(STAT_PROFIT_LONGTRADES);
profit_trades_avgcon = (int)::TesterStatistics(STAT_PROFITTRADES_AVGCON);
loss_trades_avgcon = (int)::TesterStatistics(STAT_LOSSTRADES_AVGCON);
}
};
//+------------------------------------------------------------------+
#endif // MQLCYBYLEO_SRC_BACKTESTER_RESULTS_BASE_MQH