Add Bollinger Bands Volatility Protection indicator support

- Introduced BollingerBandsVolatilityProtection indicator in GeneticService with configuration settings for period and standard deviation (stdev).
- Updated ScenarioHelpers to handle creation and validation of the new indicator type.
- Enhanced CustomScenario, backtest, and scenario pages to include BollingerBandsVolatilityProtection in indicator lists and parameter mappings.
- Modified API and types to reflect the addition of the new indicator in relevant enums and mappings.
- Updated frontend components to support new parameters and visualization for Bollinger Bands.
This commit is contained in:
2025-11-25 02:12:57 +07:00
parent 3ec1da531a
commit 6376e13b07
21 changed files with 618 additions and 220 deletions

View File

@@ -100,8 +100,11 @@ public static class ScenarioHelpers
indicator.FastPeriods.Value, indicator.SlowPeriods.Value),
IndicatorType.SuperTrendCrossEma => new SuperTrendCrossEma(indicator.Name,
indicator.Period.Value, indicator.Multiplier.Value),
IndicatorType.BollingerBandsPercentBMomentumBreakout => new BollingerBandsPercentBMomentumBreakout(indicator.Name,
indicator.Period.Value, indicator.Multiplier.Value),
IndicatorType.BollingerBandsPercentBMomentumBreakout => new BollingerBandsPercentBMomentumBreakout(
indicator.Name,
indicator.Period.Value, indicator.StDev.Value),
IndicatorType.BollingerBandsVolatilityProtection => new BollingerBandsVolatilityProtection(indicator.Name,
indicator.Period.Value, indicator.StDev.Value),
IndicatorType.IchimokuKumoTrend => new IchimokuKumoTrend(indicator.Name,
indicator.TenkanPeriods ?? 9,
indicator.KijunPeriods ?? 26,
@@ -112,6 +115,8 @@ public static class ScenarioHelpers
_ => throw new NotImplementedException(),
};
result.SignalType = GetSignalType(indicator.Type);
return result;
}
@@ -122,16 +127,24 @@ public static class ScenarioHelpers
{
return new LightIndicator(indicatorBase.Name, indicatorBase.Type)
{
SignalType = indicatorBase.SignalType,
MinimumHistory = indicatorBase.MinimumHistory,
Period = indicatorBase.Period,
FastPeriods = indicatorBase.FastPeriods,
SlowPeriods = indicatorBase.SlowPeriods,
SignalPeriods = indicatorBase.SignalPeriods,
Multiplier = indicatorBase.Multiplier,
StDev = indicatorBase.StDev,
SmoothPeriods = indicatorBase.SmoothPeriods,
StochPeriods = indicatorBase.StochPeriods,
CyclePeriods = indicatorBase.CyclePeriods
CyclePeriods = indicatorBase.CyclePeriods,
KFactor = indicatorBase.KFactor,
DFactor = indicatorBase.DFactor,
TenkanPeriods = indicatorBase.TenkanPeriods,
KijunPeriods = indicatorBase.KijunPeriods,
SenkouBPeriods = indicatorBase.SenkouBPeriods,
OffsetPeriods = indicatorBase.OffsetPeriods,
SenkouOffset = indicatorBase.SenkouOffset,
ChikouOffset = indicatorBase.ChikouOffset
};
}
@@ -143,11 +156,18 @@ public static class ScenarioHelpers
int? slowPeriods = null,
int? signalPeriods = null,
double? multiplier = null,
double? stdev = null,
int? stochPeriods = null,
int? smoothPeriods = null,
int? cyclePeriods = null,
double? kFactor = null,
double? dFactor = null)
double? dFactor = null,
int? tenkanPeriods = null,
int? kijunPeriods = null,
int? senkouBPeriods = null,
int? offsetPeriods = null,
int? senkouOffset = null,
int? chikouOffset = null)
{
IIndicator indicator = new IndicatorBase(name, type);
@@ -249,12 +269,43 @@ public static class ScenarioHelpers
{
throw new Exception($"kFactor must be greater than 0 for {indicator.Type} strategy type");
}
if (indicator.DFactor <= 0)
{
throw new Exception($"dFactor must be greater than 0 for {indicator.Type} strategy type");
}
}
break;
case IndicatorType.BollingerBandsPercentBMomentumBreakout:
case IndicatorType.BollingerBandsVolatilityProtection:
if (!period.HasValue || !stdev.HasValue)
{
throw new Exception($"Missing period or stdev for {indicator.Type} strategy type");
}
else
{
((IndicatorBase)indicator).Period = period;
((IndicatorBase)indicator).StDev = stdev;
}
break;
case IndicatorType.IchimokuKumoTrend:
if (!tenkanPeriods.HasValue || !kijunPeriods.HasValue || !senkouBPeriods.HasValue ||
!offsetPeriods.HasValue)
{
throw new Exception($"Missing Ichimoku parameters for {indicator.Type} strategy type");
}
else
{
((IndicatorBase)indicator).TenkanPeriods = tenkanPeriods;
((IndicatorBase)indicator).KijunPeriods = kijunPeriods;
((IndicatorBase)indicator).SenkouBPeriods = senkouBPeriods;
((IndicatorBase)indicator).OffsetPeriods = offsetPeriods;
((IndicatorBase)indicator).SenkouOffset = senkouOffset;
((IndicatorBase)indicator).ChikouOffset = chikouOffset;
}
break;
case IndicatorType.Stc:
case IndicatorType.LaggingStc:
@@ -299,6 +350,7 @@ public static class ScenarioHelpers
IndicatorType.LaggingStc => SignalType.Signal,
IndicatorType.SuperTrendCrossEma => SignalType.Signal,
IndicatorType.BollingerBandsPercentBMomentumBreakout => SignalType.Signal,
IndicatorType.BollingerBandsVolatilityProtection => SignalType.Context,
IndicatorType.IchimokuKumoTrend => SignalType.Trend,
_ => throw new NotImplementedException(),
};