56 public Stochastic(
string name,
int period,
int kPeriod,
int dPeriod)
59 _maximum =
new Maximum(name +
"_Max", period);
60 _minimum =
new Minimum(name +
"_Min", period);
61 _sumFastK =
new Sum(name +
"_SumFastK", kPeriod);
62 _sumSlowK =
new Sum(name +
"_SumD", dPeriod);
65 input => ComputeFastStoch(period, input),
66 fastStoch => _maximum.IsReady,
71 input => ComputeStochK(period, kPeriod, input),
72 stochK => _maximum.IsReady,
78 input => ComputeStochD(period, kPeriod, dPeriod),
79 stochD => _maximum.IsReady,
93 : this($
"STO({period},{kPeriod},{dPeriod})", period, kPeriod, dPeriod)
113 _maximum.Update(input.
Time, input.
High);
114 _minimum.Update(input.
Time, input.
Low);
128 private decimal ComputeFastStoch(
int period,
IBaseDataBar input)
130 var denominator = _maximum.Current.Value - _minimum.Current.Value;
133 if (denominator == 0m)
138 var numerator = input.
Close - _minimum.Current.Value;
139 var fastStoch = _maximum.Samples >= period ? numerator / denominator : decimal.Zero;
141 _sumFastK.Update(input.
Time, fastStoch);
142 return fastStoch * 100;
152 private decimal ComputeStochK(
int period,
int constantK,
IBaseData input)
154 var stochK = _maximum.Samples >= (period + constantK - 1) ? _sumFastK.Current.Value / constantK : decimal.Zero;
155 _sumSlowK.Update(input.
Time, stochK);
166 private decimal ComputeStochD(
int period,
int constantK,
int constantD)
168 var stochD = _maximum.Samples >= (period + constantK + constantD - 2) ? _sumSlowK.Current.Value / constantD : decimal.Zero;