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

@@ -0,0 +1,71 @@
using Managing.Domain.Candles;
using Managing.Domain.Strategies.Base;
using Skender.Stock.Indicators;
using static Managing.Common.Enums;
namespace Managing.Domain.Strategies.Context;
public class BollingerBandsVolatilityProtection : BollingerBandsBase
{
public BollingerBandsVolatilityProtection(string name, int period, double stdev) : base(name, IndicatorType.BollingerBandsVolatilityProtection, period, stdev)
{
}
/// <summary>
/// Processes Bollinger Bands volatility protection signals based on bandwidth analysis.
/// This method applies a veto filter during periods of market extremes:
/// - Blocks signals when bandwidth is extremely high (dangerous expansion) or extremely low (dead market)
/// - Validates signals when bandwidth is normal to low (excluding squeeze extremes)
/// Bandwidth = (UpperBand - LowerBand) / Sma represents market volatility
/// </summary>
/// <param name="bbResults">List of Bollinger Bands calculation results</param>
/// <param name="candles">Candles to process</param>
protected override void ProcessBollingerBandsSignals(List<BollingerBandsResult> bbResults, HashSet<Candle> candles)
{
var bbCandles = MapBollingerBandsToCandle(bbResults, candles.TakeLast(Period.Value)).ToList();
if (bbCandles.Count == 0)
return;
foreach (var currentCandle in bbCandles)
{
var width = currentCandle.Width ?? 0;
// Determine confidence based on width levels (bandwidth as % of SMA)
// Lower width = less volatility = higher confidence for trading
// Higher width = more volatility = lower confidence for trading
Confidence confidence;
if (width >= 0.15) // Extremely high volatility - dangerous expansion
{
// Block all signals during dangerous volatility expansion
confidence = Confidence.None;
}
else if (width <= 0.02) // Extremely low volatility - dead market/squeeze
{
// Block all signals in dead markets or extreme squeezes
confidence = Confidence.None;
}
else if (width <= 0.05) // Low to normal volatility - good for trading
{
// Validate signals during low volatility trending conditions
confidence = Confidence.High;
}
else if (width <= 0.10) // Normal volatility - acceptable for trading
{
// Validate signals during normal volatility conditions
confidence = Confidence.Medium;
}
else // Moderate high volatility (0.10 - 0.15)
{
// Lower confidence during elevated but not extreme volatility
confidence = Confidence.Low;
}
// Context strategies always return TradeDirection.None
// The confidence level indicates the quality of market conditions
AddSignal(currentCandle, TradeDirection.None, confidence);
}
}
}