public bool IsCriteriaFulfilled() { // Criterion Max Ambiguous Bars if (chbAmbiguousBars.Checked && Backtester.AmbiguousBars > nudAmbiguousBars.Value) { return(false); } // Criterion Min Profit per Day if (chbMinProfitPerDay.Checked && Backtester.MoneyProfitPerDay < (double)nudMinProfitPerDay.Value) { return(false); } // Criterion Max Equity Drawdown double maxEquityDrawdown = Configs.AccountInMoney ? Backtester.MaxMoneyEquityDrawdown : Backtester.MaxEquityDrawdown; if (chbMaxDrawdown.Checked && maxEquityDrawdown > (double)nudMaxDrawdown.Value) { return(false); } // Criterion Max Equity percent drawdown if (chbEquityPercent.Checked && Backtester.MoneyEquityPercentDrawdown > (double)nudEquityPercent.Value) { return(false); } // Criterion Min Trades if (chbMinTrades.Checked && Backtester.ExecutedOrders < nudMinTrades.Value) { return(false); } // Criterion Max Trades if (chbMaxTrades.Checked && Backtester.ExecutedOrders > nudMaxTrades.Value) { return(false); } // Criterion Win / Loss ratio if (chbWinLossRatio.Checked && Backtester.WinLossRatio < (double)nudWinLossRatio.Value) { return(false); } // Criterion Minimum Sharpe ratio if (chbMinSharpeRatio.Checked && Backtester.SharpeRatio < (double)nudMinSharpeRatio.Value) { return(false); } // Max consecutive losses if (chbMaxConsecLosses.Checked && Backtester.MaxConsecutiveLosses > nudMaxConsecLosses.Value) { return(false); } // Criterion Red/Green Deviation if (chbMaxRedGreenDeviation.Checked && Backtester.RedGreenBalanceDev > (double)nudMaxRedGreenDeviation.Value) { return(false); } // OOS Pattern filter if (chbOOSPatternFilter.Checked && OOSTesting) { int netBalance = Backtester.NetBalance; int oosBalance = Backtester.Balance(BarOOS); var targetBalance = (int)(oosBalance * TargetBalanceRatio); var minBalance = (int)(targetBalance * (1 - nudoosPatternPercent.Value / 100)); if (netBalance < oosBalance || netBalance < minBalance) { return(false); } } // Smooth Balance Line if (chbSmoothBalanceLines.Checked) { var checkPoints = (int)nudSmoothBalanceCheckPoints.Value; var maxPercentDeviation = (double)(nudSmoothBalancePercent.Value / 100); for (int i = 1; i <= checkPoints; i++) { int firstBar = Data.FirstBar; int bar = Data.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); } // 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); }
/// <summary> /// Check the strategy limitations /// </summary> private 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); var targetBalance = (int)(ooSbalance * _targetBalanceRatio); var minBalance = (int)(targetBalance * (1 - NUDOOSPatternPercent.Value / 100)); if (netBalance < ooSbalance || netBalance < minBalance) { return(false); } } // Smooth Balance Line if (ChbSmoothBalanceLines.Checked) { var checkPoints = (int)NUDSmoothBalanceCheckPoints.Value; var maxPercentDeviation = (double)(NUDSmoothBalancePercent.Value / 100); for (int i = 1; i <= checkPoints; i++) { int firstBar = Data.FirstBar; int bar = Data.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); }