Rename strategy to indicators

This commit is contained in:
2025-06-16 22:09:23 +07:00
parent e4f4d078b2
commit 0f7df04813
45 changed files with 477 additions and 474 deletions

View File

@@ -61,8 +61,8 @@ namespace Managing.Application.Tests
{
// Arrange
var scenario = new Scenario("FlippingScenario");
var strategy = ScenarioHelpers.BuildStrategy(StrategyType.RsiDivergence, "RsiDiv", period: 14);
scenario.AddStrategy(strategy);
var strategy = ScenarioHelpers.BuildIndicator(IndicatorType.RsiDivergence, "RsiDiv", period: 14);
scenario.AddIndicator(strategy);
var localCandles =
FileHelpers.ReadJson<List<Candle>>($"{ticker.ToString()}-{timeframe.ToString()}-candles.json");
@@ -113,8 +113,8 @@ namespace Managing.Application.Tests
{
// Arrange
var scenario = new Scenario("ScalpingScenario");
var strategy = ScenarioHelpers.BuildStrategy(StrategyType.RsiDivergence, "RsiDiv", period: 5);
scenario.AddStrategy(strategy);
var strategy = ScenarioHelpers.BuildIndicator(IndicatorType.RsiDivergence, "RsiDiv", period: 5);
scenario.AddIndicator(strategy);
var config = new TradingBotConfig
{
@@ -154,9 +154,9 @@ namespace Managing.Application.Tests
{
// Arrange
var scenario = new Scenario("ScalpingScenario");
var strategy = ScenarioHelpers.BuildStrategy(StrategyType.MacdCross, "RsiDiv", fastPeriods: 12,
var strategy = ScenarioHelpers.BuildIndicator(IndicatorType.MacdCross, "RsiDiv", fastPeriods: 12,
slowPeriods: 26, signalPeriods: 9);
scenario.AddStrategy(strategy);
scenario.AddIndicator(strategy);
var moneyManagement = new MoneyManagement()
{
@@ -198,9 +198,9 @@ namespace Managing.Application.Tests
}
[Theory]
[InlineData(Timeframe.FifteenMinutes, -6, StrategyType.Stc, BotType.ScalpingBot)]
[InlineData(Timeframe.FifteenMinutes, -6, IndicatorType.Stc, BotType.ScalpingBot)]
//[InlineData(Timeframe.FifteenMinutes, -6, Enums.StrategyType.RsiDivergenceConfirm, Enums.BotType.FlippingBot)]
public void GetBestPeriodRsiForDivergenceFlippingBot(Timeframe timeframe, int days, StrategyType strategyType,
public void GetBestPeriodRsiForDivergenceFlippingBot(Timeframe timeframe, int days, IndicatorType indicatorType,
BotType botType)
{
var result = new List<Tuple<string, int, decimal, decimal, decimal, decimal>>();
@@ -213,7 +213,7 @@ namespace Managing.Application.Tests
var periodRange = new List<int>() { 2, 7 };
var stopLossRange = new List<decimal>() { 0.005m, 0.05m, 0.005m };
var takeProfitRange = new List<decimal>() { 0.01m, 0.1m, 0.02m };
var fileIdentifier = $"{strategyType}-{timeframe}";
var fileIdentifier = $"{indicatorType}-{timeframe}";
var completedTest = 0;
var totalTests = GetTotalTrades(periodRange, stopLossRange, takeProfitRange) *
Enum.GetNames(typeof(Ticker)).Length;
@@ -232,8 +232,8 @@ namespace Managing.Application.Tests
Parallel.For(periodRange[0], periodRange[1], options, i =>
{
var scenario = new Scenario("ScalpingScenario");
var strategy = ScenarioHelpers.BuildStrategy(strategyType, "RsiDiv", period: i);
scenario.AddStrategy(strategy);
var strategy = ScenarioHelpers.BuildIndicator(indicatorType, "RsiDiv", period: i);
scenario.AddIndicator(strategy);
// -0.5 to -5
for (decimal s = stopLossRange[0]; s < stopLossRange[1]; s += stopLossRange[2])
@@ -343,9 +343,9 @@ namespace Managing.Application.Tests
[Theory]
[InlineData(Timeframe.OneHour, -30, StrategyType.MacdCross, BotType.FlippingBot)]
[InlineData(Timeframe.OneHour, -30, StrategyType.MacdCross, BotType.ScalpingBot)]
public void GetBestMMForMacdFlippingBot(Timeframe timeframe, int days, StrategyType strategyType,
[InlineData(Timeframe.OneHour, -30, IndicatorType.MacdCross, BotType.FlippingBot)]
[InlineData(Timeframe.OneHour, -30, IndicatorType.MacdCross, BotType.ScalpingBot)]
public void GetBestMMForMacdFlippingBot(Timeframe timeframe, int days, IndicatorType indicatorType,
BotType botType)
{
var result = new List<Tuple<string, decimal, decimal, decimal, decimal>>();
@@ -357,7 +357,7 @@ namespace Managing.Application.Tests
var stopLossRange = new List<decimal>() { 0.005m, 0.05m, 0.005m };
var takeProfitRange = new List<decimal>() { 0.01m, 0.1m, 0.02m };
var fileIdentifier = $"{strategyType}-{timeframe}-{botType}";
var fileIdentifier = $"{indicatorType}-{timeframe}-{botType}";
var completedTest = 0;
var totalTests = GetTotalTradeForStopLossTakeProfit(stopLossRange, takeProfitRange) *
Enum.GetNames(typeof(Ticker)).Length;
@@ -374,9 +374,9 @@ namespace Managing.Application.Tests
return;
var scenario = new Scenario("ScalpingScenario");
var strategy = ScenarioHelpers.BuildStrategy(strategyType, "RsiDiv", fastPeriods: 12,
var strategy = ScenarioHelpers.BuildIndicator(indicatorType, "RsiDiv", fastPeriods: 12,
slowPeriods: 26, signalPeriods: 9);
scenario.AddStrategy(strategy);
scenario.AddIndicator(strategy);
// -0.5 to -5
for (decimal s = stopLossRange[0]; s < stopLossRange[1]; s += stopLossRange[2])
@@ -601,8 +601,8 @@ namespace Managing.Application.Tests
Console.WriteLine("\n=== EXAMPLE SCENARIOS ===");
foreach (var scenario in scenarios.Take(3))
{
Console.WriteLine($"Scenario: {scenario.Name} ({scenario.Strategies.Count} strategies)");
foreach (var strategy in scenario.Strategies)
Console.WriteLine($"Scenario: {scenario.Name} ({scenario.Indicators.Count} strategies)");
foreach (var strategy in scenario.Indicators)
{
Console.WriteLine($" - {strategy.Name} (Type: {strategy.Type})");
}
@@ -694,7 +694,7 @@ namespace Managing.Application.Tests
var scenarioResult = new ScenarioBacktestResult
{
ScenarioName = scenario.Name,
StrategyCount = scenario.Strategies.Count,
StrategyCount = scenario.Indicators.Count,
Ticker = ticker.ToString(),
BotType = botType.ToString(),
FinalPnl = backtestResult.FinalPnl,
@@ -994,54 +994,56 @@ namespace Managing.Application.Tests
// Signal strategies
strategies.Add(new StrategyConfiguration
{
Type = StrategyType.RsiDivergence, Name = "RSI_Divergence", ParameterSets = GetRsiDivergenceParameters()
Type = IndicatorType.RsiDivergence, Name = "RSI_Divergence",
ParameterSets = GetRsiDivergenceParameters()
});
strategies.Add(new StrategyConfiguration
{
Type = StrategyType.RsiDivergenceConfirm, Name = "RSI_Divergence_Confirm",
Type = IndicatorType.RsiDivergenceConfirm, Name = "RSI_Divergence_Confirm",
ParameterSets = GetRsiDivergenceConfirmParameters()
});
strategies.Add(new StrategyConfiguration
{ Type = StrategyType.MacdCross, Name = "MACD_Cross", ParameterSets = GetMacdCrossParameters() });
{ Type = IndicatorType.MacdCross, Name = "MACD_Cross", ParameterSets = GetMacdCrossParameters() });
strategies.Add(new StrategyConfiguration
{ Type = StrategyType.EmaCross, Name = "EMA_Cross", ParameterSets = GetEmaCrossParameters() });
{ Type = IndicatorType.EmaCross, Name = "EMA_Cross", ParameterSets = GetEmaCrossParameters() });
strategies.Add(new StrategyConfiguration
{
Type = StrategyType.DualEmaCross, Name = "Dual_EMA_Cross", ParameterSets = GetDualEmaCrossParameters()
Type = IndicatorType.DualEmaCross, Name = "Dual_EMA_Cross", ParameterSets = GetDualEmaCrossParameters()
});
strategies.Add(new StrategyConfiguration
{ Type = StrategyType.SuperTrend, Name = "SuperTrend", ParameterSets = GetSuperTrendParameters() });
{ Type = IndicatorType.SuperTrend, Name = "SuperTrend", ParameterSets = GetSuperTrendParameters() });
strategies.Add(new StrategyConfiguration
{
Type = StrategyType.ChandelierExit, Name = "Chandelier_Exit",
Type = IndicatorType.ChandelierExit, Name = "Chandelier_Exit",
ParameterSets = GetChandelierExitParameters()
});
strategies.Add(new StrategyConfiguration
{ Type = StrategyType.Stc, Name = "STC", ParameterSets = GetStcParameters() });
{ Type = IndicatorType.Stc, Name = "STC", ParameterSets = GetStcParameters() });
strategies.Add(new StrategyConfiguration
{ Type = StrategyType.LaggingStc, Name = "Lagging_STC", ParameterSets = GetLaggingStcParameters() });
{ Type = IndicatorType.LaggingStc, Name = "Lagging_STC", ParameterSets = GetLaggingStcParameters() });
strategies.Add(new StrategyConfiguration
{
Type = StrategyType.ThreeWhiteSoldiers, Name = "Three_White_Soldiers",
Type = IndicatorType.ThreeWhiteSoldiers, Name = "Three_White_Soldiers",
ParameterSets = GetThreeWhiteSoldiersParameters()
});
strategies.Add(new StrategyConfiguration
{
Type = StrategyType.SuperTrendCrossEma, Name = "SuperTrend_Cross_EMA",
Type = IndicatorType.SuperTrendCrossEma, Name = "SuperTrend_Cross_EMA",
ParameterSets = GetSuperTrendCrossEmaParameters()
});
// Trend strategies
strategies.Add(new StrategyConfiguration
{ Type = StrategyType.EmaTrend, Name = "EMA_Trend", ParameterSets = GetEmaTrendParameters() });
{ Type = IndicatorType.EmaTrend, Name = "EMA_Trend", ParameterSets = GetEmaTrendParameters() });
strategies.Add(new StrategyConfiguration
{
Type = StrategyType.StochRsiTrend, Name = "StochRSI_Trend", ParameterSets = GetStochRsiTrendParameters()
Type = IndicatorType.StochRsiTrend, Name = "StochRSI_Trend",
ParameterSets = GetStochRsiTrendParameters()
});
// Context strategies
strategies.Add(new StrategyConfiguration
{ Type = StrategyType.StDev, Name = "Standard_Deviation", ParameterSets = GetStDevParameters() });
{ Type = IndicatorType.StDev, Name = "Standard_Deviation", ParameterSets = GetStDevParameters() });
return strategies;
}
@@ -1097,7 +1099,7 @@ namespace Managing.Application.Tests
foreach (var (strategyConfig, parameterSet) in strategyParams)
{
var strategy = ScenarioHelpers.BuildStrategy(
var strategy = ScenarioHelpers.BuildIndicator(
strategyConfig.Type,
$"{strategyConfig.Name}_{parameterSet.Name}",
period: parameterSet.Period,
@@ -1109,7 +1111,7 @@ namespace Managing.Application.Tests
smoothPeriods: parameterSet.SmoothPeriods,
cyclePeriods: parameterSet.CyclePeriods);
scenario.AddStrategy(strategy);
scenario.AddIndicator(strategy);
}
return scenario;
@@ -1449,7 +1451,7 @@ namespace Managing.Application.Tests
public class StrategyConfiguration
{
public StrategyType Type { get; set; }
public IndicatorType Type { get; set; }
public string Name { get; set; }
public List<ParameterSet> ParameterSets { get; set; } = new();
}