Add StochasticCross indicator support in GeneticService and related classes
- Introduced StochasticCross indicator type in GeneticService with configuration settings for stochPeriods, signalPeriods, smoothPeriods, kFactor, and dFactor. - Updated IIndicator interface and IndicatorBase class to include KFactor and DFactor properties. - Enhanced LightIndicator class to support new properties and ensure proper conversion back to full Indicator. - Modified ScenarioHelpers to handle StochasticCross indicator creation and validation, ensuring default values and error handling for kFactor and dFactor.
This commit is contained in:
@@ -91,6 +91,9 @@ public static class ScenarioHelpers
|
||||
IndicatorType.StochRsiTrend => new StochRsiTrendIndicatorBase(indicator.Name,
|
||||
indicator.Period.Value, indicator.StochPeriods.Value, indicator.SignalPeriods.Value,
|
||||
indicator.SmoothPeriods.Value),
|
||||
IndicatorType.StochasticCross => new StochasticCrossIndicator(indicator.Name,
|
||||
indicator.StochPeriods.Value, indicator.SignalPeriods.Value, indicator.SmoothPeriods.Value,
|
||||
indicator.KFactor ?? 3.0, indicator.DFactor ?? 2.0),
|
||||
IndicatorType.Stc => new StcIndicatorBase(indicator.Name, indicator.CyclePeriods.Value,
|
||||
indicator.FastPeriods.Value, indicator.SlowPeriods.Value),
|
||||
IndicatorType.LaggingStc => new LaggingSTC(indicator.Name, indicator.CyclePeriods.Value,
|
||||
@@ -133,7 +136,9 @@ public static class ScenarioHelpers
|
||||
double? multiplier = null,
|
||||
int? stochPeriods = null,
|
||||
int? smoothPeriods = null,
|
||||
int? cyclePeriods = null)
|
||||
int? cyclePeriods = null,
|
||||
double? kFactor = null,
|
||||
double? dFactor = null)
|
||||
{
|
||||
IIndicator indicator = new IndicatorBase(name, type);
|
||||
|
||||
@@ -214,6 +219,33 @@ public static class ScenarioHelpers
|
||||
indicator.SmoothPeriods = smoothPeriods;
|
||||
}
|
||||
|
||||
break;
|
||||
case IndicatorType.StochasticCross:
|
||||
if (!stochPeriods.HasValue || !signalPeriods.HasValue || !smoothPeriods.HasValue)
|
||||
{
|
||||
throw new Exception(
|
||||
$"Missing stochPeriods, signalPeriods, smoothPeriods for {indicator.Type} strategy type");
|
||||
}
|
||||
else
|
||||
{
|
||||
indicator.StochPeriods = stochPeriods;
|
||||
indicator.SignalPeriods = signalPeriods;
|
||||
indicator.SmoothPeriods = smoothPeriods;
|
||||
// Set default values for optional parameters
|
||||
indicator.KFactor = kFactor ?? 3.0;
|
||||
indicator.DFactor = dFactor ?? 2.0;
|
||||
|
||||
// Validate kFactor and dFactor are greater than 0
|
||||
if (indicator.KFactor <= 0)
|
||||
{
|
||||
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.Stc:
|
||||
case IndicatorType.LaggingStc:
|
||||
@@ -252,6 +284,7 @@ public static class ScenarioHelpers
|
||||
IndicatorType.EmaTrend => SignalType.Trend,
|
||||
IndicatorType.Composite => SignalType.Signal,
|
||||
IndicatorType.StochRsiTrend => SignalType.Trend,
|
||||
IndicatorType.StochasticCross => SignalType.Signal,
|
||||
IndicatorType.Stc => SignalType.Signal,
|
||||
IndicatorType.StDev => SignalType.Context,
|
||||
IndicatorType.LaggingStc => SignalType.Signal,
|
||||
|
||||
Reference in New Issue
Block a user