bool IsLimitationsFulfilled()
{
// The calculated strategy has higher profit
// or the same profit but lower number of slots
Backtester.CalculateAccountStats();
// Limitation Max Ambiguous Bars
if (chbAmbiguousBars.Checked && Backtester.AmbiguousBars > nudAmbiguousBars.Value)
return false;
// Limitation Max Equity Drawdown
double maxEquityDrawdown = Configs.AccountInMoney ? Backtester.MaxMoneyEquityDrawdown : Backtester.MaxEquityDrawdown;
if (chbMaxDrawdown.Checked && maxEquityDrawdown > (double)nudMaxDrawdown.Value)
return false;
// Limitation Max Equity percent drawdown
if (chbEquityPercent.Checked && Backtester.MoneyEquityPercentDrawdown > (double)nudEquityPercent.Value)
return false;
// Limitation Min Trades
if (chbMinTrades.Checked && Backtester.ExecutedOrders < nudMinTrades.Value)
return false;
// Limitation Max Trades
if (chbMaxTrades.Checked && Backtester.ExecutedOrders > nudMaxTrades.Value)
return false;
// Limitation Win / Loss ratio
if (chbWinLossRatio.Checked && Backtester.WinLossRatio < (double)nudWinLossRatio.Value)
return false;
// OOS Pattern filter
if (chbOOSPatternFilter.Checked && chbOutOfSample.Checked)
{
int netBalance = Backtester.NetBalance;
int OOSbalance = Backtester.Balance(barOOS);
int targetBalance = (int)(OOSbalance * targetBalanceRatio);
int minBalance = (int)(targetBalance * (1 - nudOOSPatternPercent.Value / 100));
if (netBalance < OOSbalance || netBalance < minBalance)
return false;
}
// Smooth Balance Line
if (chbSmoothBalanceLines.Checked)
{
int checkPoints = (int)nudSmoothBalanceCheckPoints.Value;
double maxPercentDeviation = (double)(nudSmoothBalancePercent.Value / 100);
for (int i = 1; i <= checkPoints; i++)
{
int firstBar = Backtester.FirstBar;
int bar = Backtester.FirstBar + i * (Data.Bars - firstBar) / (checkPoints + 1);
double netBalance = Backtester.NetMoneyBalance;
double startBalance = Backtester.MoneyBalance(firstBar);
double checkPointBalance = Backtester.MoneyBalance(bar);
double targetBalance = startBalance + i * (netBalance - startBalance) / (checkPoints + 1);
double minBalance = targetBalance * (1 - maxPercentDeviation);
double maxBalance = targetBalance * (1 + maxPercentDeviation);
if (checkPointBalance < minBalance || checkPointBalance > maxBalance)
return false;
if (Configs.AdditionalStatistics)
{
// Long balance line
netBalance = Backtester.NetLongMoneyBalance;
checkPointBalance = Backtester.LongMoneyBalance(bar);
startBalance = Backtester.LongMoneyBalance(firstBar);
targetBalance = startBalance + i * (netBalance - startBalance) / (checkPoints + 1);
minBalance = targetBalance * (1 - maxPercentDeviation);
maxBalance = targetBalance * (1 + maxPercentDeviation);
if (checkPointBalance < minBalance || checkPointBalance > maxBalance)
return false;
// Short balance line
netBalance = Backtester.NetShortMoneyBalance;
checkPointBalance = Backtester.ShortMoneyBalance(bar);
startBalance = Backtester.ShortMoneyBalance(firstBar);
targetBalance = startBalance + i * (netBalance - startBalance) / (checkPoints + 1);
minBalance = targetBalance * (1 - maxPercentDeviation);
maxBalance = targetBalance * (1 + maxPercentDeviation);
if (checkPointBalance < minBalance || checkPointBalance > maxBalance)
return false;
}
}
}
return true;
}