diff --git a/SyntheticVendor/SyntheticVendor.cs b/SyntheticVendor/SyntheticVendor.cs index 913041a4..6566b19b 100644 --- a/SyntheticVendor/SyntheticVendor.cs +++ b/SyntheticVendor/SyntheticVendor.cs @@ -486,8 +486,8 @@ public class SyntheticVendor : Vendor // Calculate the sine wave values double frequency = 2 * Math.PI / 1500; // Complete cycle over 25 hours - double value = 50 + 50 * Math.Sin(cyclePosition * frequency); // Oscillate between 0 and 100 - double nextValue = 50 + 50 * Math.Sin((cyclePosition + slice.TotalMinutes) * frequency); + double value = 50 + (50 * Math.Sin(cyclePosition * frequency)); // Oscillate between 0 and 100 + double nextValue = 50 + (50 * Math.Sin((cyclePosition + slice.TotalMinutes) * frequency)); double factor = 0.6 * Math.Abs(nextValue - value); @@ -537,7 +537,7 @@ public class SyntheticVendor : Vendor openValue = 100; closeValue = 0.0001; } - else if (hoursInDay < slice.TotalHours / 2 || hoursInDay > 24 - slice.TotalHours / 2) + else if (hoursInDay < slice.TotalHours / 2 || hoursInDay > 24 - (slice.TotalHours / 2)) { // Transition from 0 to 100 at midnight openValue = 0.0001; @@ -566,8 +566,8 @@ public class SyntheticVendor : Vendor double hours = (time - DateTime.UnixEpoch).TotalHours; double period = 24; // 24-hour period double position = hours % period; - double value = 200 * (position / period) - 100; - double nextValue = 200 * ((position + slice.TotalHours) % period / period) - 100; + double value = (200 * (position / period)) - 100; + double nextValue = (200 * (((position + slice.TotalHours) % period) / period)) - 100; return new HistoryItemBar { @@ -588,7 +588,7 @@ public class SyntheticVendor : Vendor double period = 24; // 24-hour period double position = hours % period; double value = 100 - (200 * (position / period)); - double nextValue = 100 - (200 * ((position + slice.TotalHours) % period / period)); + double nextValue = 100 - (200 * (((position + slice.TotalHours) % period) / period)); return new HistoryItemBar { @@ -628,8 +628,8 @@ public class SyntheticVendor : Vendor double hours = (time - DateTime.UnixEpoch).TotalHours; double period = 24; double position = hours % period; - double value = 200 * (Math.Abs(position / period - 0.5) - 0.25) * 100; - double nextValue = 200 * (Math.Abs(((position + slice.TotalHours) % period) / period - 0.5) - 0.25) * 100; + double value = 200 * (Math.Abs((position / period) - 0.5) - 0.25) * 100; + double nextValue = 200 * (Math.Abs((((position + slice.TotalHours) % period) / period) - 0.5) - 0.25) * 100; return new HistoryItemBar { @@ -651,7 +651,7 @@ public class SyntheticVendor : Vendor double frequency = 2 * Math.PI / period; // Full cycle over 24 hours // Adjust time to center the main peak at 12 hours - double t = minutes % period - period / 2; + double t = (minutes % period) - (period / 2); // Scale factor double scaleFactor = 7.0; @@ -661,7 +661,7 @@ public class SyntheticVendor : Vendor double sincValue = x != 0 ? 100 * Math.Sin(x) / x : 100; // Calculate next value - double nextT = ((minutes + slice.TotalMinutes) % period) - period / 2; + double nextT = ((minutes + slice.TotalMinutes) % period) - (period / 2); double nextX = scaleFactor * frequency * nextT; double nextSincValue = nextX != 0 ? 100 * Math.Sin(nextX) / nextX : 100; @@ -701,7 +701,7 @@ public class SyntheticVendor : Vendor double value; if (position < pulsePeriod) { - value = amplitude * Math.Exp(-Math.Pow(position - center, 2) / (2 * Math.Pow(width, 2))) + baselineValue; + value = (amplitude * Math.Exp(-Math.Pow(position - center, 2) / (2 * Math.Pow(width, 2)))) + baselineValue; } else { @@ -713,7 +713,7 @@ public class SyntheticVendor : Vendor double nextValue; if (nextPosition < pulsePeriod) { - nextValue = amplitude * Math.Exp(-Math.Pow(nextPosition - center, 2) / (2 * Math.Pow(width, 2))) + baselineValue; + nextValue = (amplitude * Math.Exp(-Math.Pow(nextPosition - center, 2) / (2 * Math.Pow(width, 2)))) + baselineValue; } else { @@ -875,9 +875,9 @@ public class SyntheticVendor : Vendor double meanReversionStrength = 0.1; double openNoise = random.NextDouble(); - double open = previousClose + volatility * openNoise + meanReversionStrength * (meanPrice - previousClose); + double open = previousClose + (volatility * openNoise) + (meanReversionStrength * (meanPrice - previousClose)); double closeNoise = random.NextDouble(); - double close = open + volatility * closeNoise + meanReversionStrength * (meanPrice - open); + double close = open + (volatility * closeNoise) + (meanReversionStrength * (meanPrice - open)); // Determine High and Low double high = Math.Max(open, close); @@ -890,7 +890,7 @@ public class SyntheticVendor : Vendor double lowNoise = Math.Abs(random.NextDouble()); low -= volatility * lowNoise; - double volume = Math.Abs(random.NextDouble()) * 1000 + 100; + double volume = (Math.Abs(random.NextDouble()) * 1000) + 100; previousClose = close; @@ -923,11 +923,11 @@ public class SyntheticVendor : Vendor // Generate open price double openNoise = GeneratePinkNoiseValue(); - double open = previousClose + volatility * openNoise + meanReversionStrength * (meanPrice - previousClose); + double open = previousClose + (volatility * openNoise) + (meanReversionStrength * (meanPrice - previousClose)); // Generate close price double closeNoise = GeneratePinkNoiseValue(); - double close = open + volatility * closeNoise + meanReversionStrength * (meanPrice - open); + double close = open + (volatility * closeNoise) + (meanReversionStrength * (meanPrice - open)); // Determine High and Low double high = Math.Max(open, close); @@ -940,7 +940,7 @@ public class SyntheticVendor : Vendor double lowNoise = Math.Abs(GeneratePinkNoiseValue()); low -= volatility * lowNoise; - double volume = Math.Abs(GeneratePinkNoiseValue()) * 1000 + 100; + double volume = (Math.Abs(GeneratePinkNoiseValue()) * 1000) + 100; // Update previous close for the next iteration previousClose = close; @@ -967,7 +967,7 @@ public class SyntheticVendor : Vendor for (int i = 0; i < NumOctaves; i++) { - double white = random.NextDouble() * 2 - 1; + double white = (random.NextDouble() * 2) - 1; pinkNoiseState[i] = (pinkNoiseState[i] + white) * 0.5; total += pinkNoiseState[i] * Math.Pow(2, -i); } @@ -1015,7 +1015,7 @@ public class SyntheticVendor : Vendor double u1 = 1.0 - random.NextDouble(); // Uniform(0,1] random doubles double u2 = 1.0 - random.NextDouble(); double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2); - return mean + stdDev * randStdNormal; + return mean + (stdDev * randStdNormal); } @@ -1033,7 +1033,7 @@ public class SyntheticVendor : Vendor double epsilon = GenerateGaussian(0, 1); // Calculate the price movement using GBM equation - double drift = (GBMMu - 0.5 * GBMSigma * GBMSigma) * dt; + double drift = (GBMMu - (0.5 * GBMSigma * GBMSigma)) * dt; double diffusion = GBMSigma * Math.Sqrt(dt) * epsilon; double returnValue = Math.Exp(drift + diffusion); @@ -1046,11 +1046,11 @@ public class SyntheticVendor : Vendor // Generate High and Low values double highLowRange = Math.Max(Math.Abs(close - open), GBMLastClose * GBMSigma * Math.Sqrt(dt) * Math.Abs(GenerateGaussian(0, 1))); - double high = Math.Max(open, close) + highLowRange * 0.5; - double low = Math.Min(open, close) - highLowRange * 0.5; + double high = Math.Max(open, close) + (highLowRange * 0.5); + double low = Math.Min(open, close) - (highLowRange * 0.5); // Generate volume (you may want to adjust this based on your needs) - double volume = Math.Max(100, 1000 * Math.Abs(close - open) + 500 * GenerateGaussian(0, 1)); + double volume = Math.Max(100, (1000 * Math.Abs(close - open)) + (500 * GenerateGaussian(0, 1))); // Update last close for next iteration GBMLastClose = close; @@ -1089,11 +1089,11 @@ public class SyntheticVendor : Vendor double highLowRange = Math.Max(Math.Abs(close - open), FBMLastClose * FBMSigma * Math.Pow(dt, FBMHurst) * Math.Abs(GenerateFractionalGaussianNoise(FBMHurst)) * 2); - double high = Math.Max(open, close) + highLowRange * 0.5; - double low = Math.Min(open, close) - highLowRange * 0.5; + double high = Math.Max(open, close) + (highLowRange * 0.5); + double low = Math.Min(open, close) - (highLowRange * 0.5); - double volume = Math.Max(100, 2000 * Math.Abs(close - open) + - 1000 * Math.Abs(GenerateFractionalGaussianNoise(FBMHurst))); + double volume = Math.Max(100, (2000 * Math.Abs(close - open)) + + (1000 * Math.Abs(GenerateFractionalGaussianNoise(FBMHurst)))); FBMLastClose = close; diff --git a/Tests/test_eventing.cs b/Tests/test_eventing.cs index 78ad4f8e..d997b81b 100644 --- a/Tests/test_eventing.cs +++ b/Tests/test_eventing.cs @@ -135,7 +135,7 @@ public class EventingTests randomValue, randomValue + Math.Abs(GetRandomDouble(rng) * 10), randomValue - Math.Abs(GetRandomDouble(rng) * 10), - randomValue + GetRandomDouble(rng) * 5, + randomValue + (GetRandomDouble(rng) * 5), Math.Abs(GetRandomDouble(rng) * 1000), true ); diff --git a/Tests/test_iTBar.cs b/Tests/test_iTBar.cs index 59796179..3482e4d5 100644 --- a/Tests/test_iTBar.cs +++ b/Tests/test_iTBar.cs @@ -125,10 +125,10 @@ public class BarIndicatorTests /// A randomly generated TBar. private TBar GenerateRandomBar(bool isNew) { - double open = GetRandomDouble() * 200 - 100; - double close = GetRandomDouble() * 200 - 100; - double high = Math.Max(open, close) + GetRandomDouble() * 10; - double low = Math.Min(open, close) - GetRandomDouble() * 10; + double open = (GetRandomDouble() * 200) - 100; + double close = (GetRandomDouble() * 200) - 100; + double high = Math.Max(open, close) + (GetRandomDouble() * 10); + double low = Math.Min(open, close) - (GetRandomDouble() * 10); long volume = GetRandomNumber(0, 10000); return new TBar(Time: DateTime.Now, Open: open, High: high, Low: low, Close: close, Volume: volume, IsNew: isNew); diff --git a/Tests/test_updates_averages.cs b/Tests/test_updates_averages.cs index 2c06f8c5..36b154d0 100644 --- a/Tests/test_updates_averages.cs +++ b/Tests/test_updates_averages.cs @@ -14,7 +14,7 @@ public class AveragesUpdateTests { byte[] bytes = new byte[8]; rng.GetBytes(bytes); - return (double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue * 200 - 100; // Range: -100 to 100 + return ((double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue * 200) - 100; // Range: -100 to 100 } [Fact] diff --git a/Tests/test_updates_errors.cs b/Tests/test_updates_errors.cs index 13641eb8..8af37f5e 100644 --- a/Tests/test_updates_errors.cs +++ b/Tests/test_updates_errors.cs @@ -14,7 +14,7 @@ public class UpdateTests { byte[] bytes = new byte[8]; rng.GetBytes(bytes); - return (double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue * 200 - 100; // Range: -100 to 100 + return ((double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue * 200) - 100; // Range: -100 to 100 } [Fact] diff --git a/Tests/test_updates_momentum.cs b/Tests/test_updates_momentum.cs index 4f8c3028..96b2930d 100644 --- a/Tests/test_updates_momentum.cs +++ b/Tests/test_updates_momentum.cs @@ -14,7 +14,7 @@ public class MomentumUpdateTests { byte[] bytes = new byte[8]; rng.GetBytes(bytes); - return (double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue * 200 - 100; // Range: -100 to 100 + return ((double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue * 200) - 100; // Range: -100 to 100 } private TBar GetRandomBar(bool IsNew) @@ -22,7 +22,7 @@ public class MomentumUpdateTests double open = GetRandomDouble(); double high = open + Math.Abs(GetRandomDouble()); double low = open - Math.Abs(GetRandomDouble()); - double close = low + (high - low) * GetRandomDouble(); + double close = low + ((high - low) * GetRandomDouble()); return new TBar(DateTime.Now, open, high, low, close, 1000, IsNew); } diff --git a/Tests/test_updates_oscillators.cs b/Tests/test_updates_oscillators.cs index a9d74a8e..12f55626 100644 --- a/Tests/test_updates_oscillators.cs +++ b/Tests/test_updates_oscillators.cs @@ -14,7 +14,7 @@ public class OscillatorsUpdateTests { byte[] bytes = new byte[8]; rng.GetBytes(bytes); - return (double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue * 200 - 100; // Range: -100 to 100 + return ((double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue * 200) - 100; // Range: -100 to 100 } [Fact] diff --git a/Tests/test_updates_statistics.cs b/Tests/test_updates_statistics.cs index 6fca5957..d1820474 100644 --- a/Tests/test_updates_statistics.cs +++ b/Tests/test_updates_statistics.cs @@ -14,7 +14,7 @@ public class StatisticsUpdateTests { byte[] bytes = new byte[8]; rng.GetBytes(bytes); - return (double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue * 200 - 100; // Range: -100 to 100 + return ((double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue * 200) - 100; // Range: -100 to 100 } [Fact] diff --git a/Tests/test_updates_volatility.cs b/Tests/test_updates_volatility.cs index bf9fabec..c48a2d9e 100644 --- a/Tests/test_updates_volatility.cs +++ b/Tests/test_updates_volatility.cs @@ -14,7 +14,7 @@ public class VolatilityUpdateTests { byte[] bytes = new byte[8]; rng.GetBytes(bytes); - return (double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue * 200 - 100; // Range: -100 to 100 + return ((double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue * 200) - 100; // Range: -100 to 100 } private TBar GetRandomBar(bool IsNew) @@ -22,7 +22,7 @@ public class VolatilityUpdateTests double open = GetRandomDouble(); double high = open + Math.Abs(GetRandomDouble()); double low = open - Math.Abs(GetRandomDouble()); - double close = low + (high - low) * GetRandomDouble(); + double close = low + ((high - low) * GetRandomDouble()); return new TBar(DateTime.Now, open, high, low, close, 1000, IsNew); } diff --git a/Tests/test_updates_volume.cs b/Tests/test_updates_volume.cs index 66058a26..166a5326 100644 --- a/Tests/test_updates_volume.cs +++ b/Tests/test_updates_volume.cs @@ -13,7 +13,7 @@ public class VolumeUpdateTests { byte[] bytes = new byte[8]; rng.GetBytes(bytes); - return (double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue * 200 - 100; // Range: -100 to 100 + return ((double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue * 200) - 100; // Range: -100 to 100 } private TBar GetRandomBar(bool IsNew) @@ -21,7 +21,7 @@ public class VolumeUpdateTests double open = GetRandomDouble(); double high = open + Math.Abs(GetRandomDouble()); double low = open - Math.Abs(GetRandomDouble()); - double close = low + (high - low) * GetRandomDouble(); + double close = low + ((high - low) * GetRandomDouble()); double volume = Math.Abs(GetRandomDouble()) * 1000; // Random positive volume return new TBar(DateTime.Now, open, high, low, close, volume, IsNew); } diff --git a/lib/averages/Afirma.cs b/lib/averages/Afirma.cs index 0d7f1aa2..e8b0a76c 100644 --- a/lib/averages/Afirma.cs +++ b/lib/averages/Afirma.cs @@ -60,12 +60,12 @@ public class Afirma : AbstractBase _n = (Taps - 1) / 2; // Precalculate least squares coefficients - _sx2 = (2 * _n + 1) / 3.0; + _sx2 = ((2 * _n) + 1) / 3.0; _sx3 = _n * (_n + 1) / 2.0; - _sx4 = _sx2 * (3 * _n * _n + 3 * _n - 1) / 5.0; - _sx5 = _sx3 * (2 * _n * _n + 2 * _n - 1) / 3.0; - _sx6 = _sx2 * (3 * Math.Pow(_n, 3) * (_n + 2) - 3 * _n + 1) / 7.0; - _den = _sx6 * _sx4 / _sx5 - _sx5; + _sx4 = _sx2 * ((3 * _n * _n) + (3 * _n) - 1) / 5.0; + _sx5 = _sx3 * ((2 * _n * _n) + (2 * _n) - 1) / 3.0; + _sx6 = _sx2 * ((3 * Math.Pow(_n, 3) * (_n + 2)) - (3 * _n) + 1) / 7.0; + _den = (_sx6 * _sx4 / _sx5) - _sx5; Name = "Afirma"; Init(); @@ -105,15 +105,15 @@ public class Afirma : AbstractBase case WindowType.Rectangular: return 1.0; case WindowType.Hanning1: - return 0.50 - 0.50 * Math.Cos(_twoPi * k / tapsMinusOne); + return 0.50 - (0.50 * Math.Cos(_twoPi * k / tapsMinusOne)); case WindowType.Hanning2: - return 0.54 - 0.46 * Math.Cos(_twoPi * k / tapsMinusOne); + return 0.54 - (0.46 * Math.Cos(_twoPi * k / tapsMinusOne)); case WindowType.Blackman: - return 0.42 - 0.50 * Math.Cos(_twoPi * k / tapsMinusOne) + 0.08 * Math.Cos(_fourPi * k / tapsMinusOne); + return 0.42 - (0.50 * Math.Cos(_twoPi * k / tapsMinusOne)) + (0.08 * Math.Cos(_fourPi * k / tapsMinusOne)); case WindowType.BlackmanHarris: - return 0.35875 - 0.48829 * Math.Cos(_twoPi * k / tapsMinusOne) + - 0.14128 * Math.Cos(_fourPi * k / tapsMinusOne) - - 0.01168 * Math.Cos(_sixPi * k / tapsMinusOne); + return 0.35875 - (0.48829 * Math.Cos(_twoPi * k / tapsMinusOne)) + + (0.14128 * Math.Cos(_fourPi * k / tapsMinusOne)) - + (0.01168 * Math.Cos(_sixPi * k / tapsMinusOne)); default: return 1.0; } @@ -156,15 +156,15 @@ public class Afirma : AbstractBase sx2y = 2.0 * sx2y / _n / (_n + 1); sx3y = 2.0 * sx3y / _n / (_n + 1); - double p = sx2y - a0 * _sx2 - a1 * _sx3; - double q = sx3y - a0 * _sx3 - a1 * _sx4; - double a2 = (p * _sx6 / _sx5 - q) / _den; - double a3 = (q * _sx4 / _sx5 - p) / _den; + double p = sx2y - (a0 * _sx2) - (a1 * _sx3); + double q = sx3y - (a0 * _sx3) - (a1 * _sx4); + double a2 = ((p * _sx6 / _sx5) - q) / _den; + double a3 = ((q * _sx4 / _sx5) - p) / _den; for (int k = 0; k <= _n; k++) { double k2 = k * k; - _armaBuffer[_n - k] = a0 + k * a1 + k2 * a2 + k2 * k * a3; + _armaBuffer[_n - k] = a0 + (k * a1) + (k2 * a2) + (k2 * k * a3); } } diff --git a/lib/averages/Convolution.cs b/lib/averages/Convolution.cs index 08162bc8..ecba18b4 100644 --- a/lib/averages/Convolution.cs +++ b/lib/averages/Convolution.cs @@ -123,10 +123,10 @@ public class Convolution : AbstractBase int i = 0; while (i <= offset - 3) { - sum += bufferSpan[offset - i] * _normalizedKernel[i] + - bufferSpan[offset - (i + 1)] * _normalizedKernel[i + 1] + - bufferSpan[offset - (i + 2)] * _normalizedKernel[i + 2] + - bufferSpan[offset - (i + 3)] * _normalizedKernel[i + 3]; + sum += (bufferSpan[offset - i] * _normalizedKernel[i]) + + (bufferSpan[offset - (i + 1)] * _normalizedKernel[i + 1]) + + (bufferSpan[offset - (i + 2)] * _normalizedKernel[i + 2]) + + (bufferSpan[offset - (i + 3)] * _normalizedKernel[i + 3]); i += 4; } diff --git a/lib/averages/Dema.cs b/lib/averages/Dema.cs index d0673ae4..f70ae547 100644 --- a/lib/averages/Dema.cs +++ b/lib/averages/Dema.cs @@ -75,7 +75,7 @@ public class Dema : AbstractBase [MethodImpl(MethodImplOptions.AggressiveInlining)] private double CalculateEma(double input, double lastEma) { - return _k * (input - lastEma) + lastEma; + return (_k * (input - lastEma)) + lastEma; } protected override double Calculation() @@ -96,7 +96,7 @@ public class Dema : AbstractBase _lastEma2 = ema2; // Calculate final DEMA - double result = 2 * compensatedEma1 - (ema2 * invE); + double result = (2 * compensatedEma1) - (ema2 * invE); IsHot = _index >= WarmupPeriod; return result; diff --git a/lib/averages/Dsma.cs b/lib/averages/Dsma.cs index 70f80191..eab4d489 100644 --- a/lib/averages/Dsma.cs +++ b/lib/averages/Dsma.cs @@ -116,7 +116,7 @@ public class Dsma : AbstractBase [MethodImpl(MethodImplOptions.AggressiveInlining)] private double CalculateSuperSmootherFilter() { - return _c1Half * (_zeros + _zeros1) + _c2 * _filt1 + _c3 * _filt2; + return (_c1Half * (_zeros + _zeros1)) + (_c2 * _filt1) + (_c3 * _filt2); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -155,7 +155,7 @@ public class Dsma : AbstractBase double alpha = CalculateAdaptiveAlpha(scaledFilt); // DSMA calculation - double dsma = alpha * Input.Value + (1 - alpha) * _lastDsma; + double dsma = (alpha * Input.Value) + ((1 - alpha) * _lastDsma); // Update state variables _zeros1 = _zeros; diff --git a/lib/averages/Dwma.cs b/lib/averages/Dwma.cs index 88c87c7b..76147573 100644 --- a/lib/averages/Dwma.cs +++ b/lib/averages/Dwma.cs @@ -38,7 +38,7 @@ public class Dwma : AbstractBase _innerWma = new Wma(period); _outerWma = new Wma(period); Name = "Dwma"; - WarmupPeriod = 2 * period - 1; + WarmupPeriod = (2 * period) - 1; Init(); } diff --git a/lib/averages/Ema.cs b/lib/averages/Ema.cs index 7ebd8014..0470dac9 100644 --- a/lib/averages/Ema.cs +++ b/lib/averages/Ema.cs @@ -112,7 +112,7 @@ public class Ema : AbstractBase [MethodImpl(MethodImplOptions.AggressiveInlining)] private double CalculateEma(double input, double lastEma) { - return _k * (input - lastEma) + lastEma; + return (_k * (input - lastEma)) + lastEma; } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/lib/averages/Epma.cs b/lib/averages/Epma.cs index 170a0319..e3c256ae 100644 --- a/lib/averages/Epma.cs +++ b/lib/averages/Epma.cs @@ -75,8 +75,8 @@ public class Epma : AbstractBase { // Using arithmetic sequence sum formula: n(a1 + an)/2 // where a1 = (2p-1) and an = (2p-1) - 3(n-1) - double firstTerm = 2 * period - 1; - double lastTerm = firstTerm - 3 * (period - 1); + double firstTerm = (2 * period) - 1; + double lastTerm = firstTerm - (3 * (period - 1)); return period * (firstTerm + lastTerm) * 0.5; } @@ -109,11 +109,11 @@ public class Epma : AbstractBase double[] kernel = new double[period]; double weightSum = CalculateKernelSum(period); double invWeightSum = 1.0 / weightSum; - double baseWeight = 2 * period - 1; + double baseWeight = (2 * period) - 1; for (int i = 0; i < period; i++) { - kernel[i] = (baseWeight - 3 * i) * invWeightSum; + kernel[i] = (baseWeight - (3 * i)) * invWeightSum; } return kernel; diff --git a/lib/averages/Frama.cs b/lib/averages/Frama.cs index aa4adaca..b0c4320c 100644 --- a/lib/averages/Frama.cs +++ b/lib/averages/Frama.cs @@ -139,7 +139,7 @@ public class Frama : AbstractBase double dimension = (System.Math.Log(n2 + _epsilon) - System.Math.Log(n1 + _epsilon)) / _log2; double alpha = CalculateAlpha(dimension); - _lastFrama = alpha * (Input.Value - _lastFrama) + _lastFrama; + _lastFrama = (alpha * (Input.Value - _lastFrama)) + _lastFrama; IsHot = _index >= WarmupPeriod; return _lastFrama; diff --git a/lib/averages/Hma.cs b/lib/averages/Hma.cs index 20e4b833..da8fccb1 100644 --- a/lib/averages/Hma.cs +++ b/lib/averages/Hma.cs @@ -117,7 +117,7 @@ public class Hma : AbstractBase double wmaFullResult = _wmaFull.Calc(Input).Value; // Calculate 2*WMA(n/2) - WMA(n) - double intermediateResult = 2.0 * wmaHalfResult - wmaFullResult; + double intermediateResult = (2.0 * wmaHalfResult) - wmaFullResult; // Calculate final WMA var finalInput = new TValue(Input.Time, intermediateResult, Input.IsNew); diff --git a/lib/averages/Htit.cs b/lib/averages/Htit.cs index ea6dd6eb..149f3c4f 100644 --- a/lib/averages/Htit.cs +++ b/lib/averages/Htit.cs @@ -82,13 +82,13 @@ public class Htit : AbstractBase [MethodImpl(MethodImplOptions.AggressiveInlining)] private static double CalculateSmoothedPrice(double p0, double p1, double p2, double p3) { - return (4.0 * p0 + 3.0 * p1 + 2.0 * p2 + p3) * 0.1; + return ((4.0 * p0) + (3.0 * p1) + (2.0 * p2) + p3) * 0.1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static double CalculateHilbertTransform(double b0, double b2, double b4, double b6, double adj) { - return (0.0962 * (b0 - b6) + 0.5769 * (b2 - b4)) * adj; + return ((0.0962 * (b0 - b6)) + (0.5769 * (b2 - b4))) * adj; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -122,7 +122,7 @@ public class Htit : AbstractBase return pr; } - double adj = 0.075 * _lastPd + 0.54; + double adj = (0.075 * _lastPd) + 0.54; // Smooth and detrender double sp = CalculateSmoothedPrice(_priceBuffer[0], _priceBuffer[1], _priceBuffer[2], _priceBuffer[3]); @@ -143,15 +143,15 @@ public class Htit : AbstractBase double jQ = CalculateHilbertTransform(_q1Buffer[0], _q1Buffer[2], _q1Buffer[4], _q1Buffer[6], adj); // Phasor addition for 3-bar averaging - double i2 = ALPHA * (i1 - jQ) + BETA * _i2Buffer[0]; - double q2 = ALPHA * (q1 + jI) + BETA * _q2Buffer[0]; + double i2 = (ALPHA * (i1 - jQ)) + (BETA * _i2Buffer[0]); + double q2 = (ALPHA * (q1 + jI)) + (BETA * _q2Buffer[0]); _i2Buffer.Add(i2, Input.IsNew); _q2Buffer.Add(q2, Input.IsNew); // Homodyne discriminator - double re = ALPHA * (i2 * _i2Buffer[1] + q2 * _q2Buffer[1]) + BETA * _reBuffer[0]; - double im = ALPHA * (i2 * _q2Buffer[1] - q2 * _i2Buffer[1]) + BETA * _imBuffer[0]; + double re = (ALPHA * ((i2 * _i2Buffer[1]) + (q2 * _q2Buffer[1]))) + (BETA * _reBuffer[0]); + double im = (ALPHA * ((i2 * _q2Buffer[1]) - (q2 * _i2Buffer[1]))) + (BETA * _imBuffer[0]); _reBuffer.Add(re, Input.IsNew); _imBuffer.Add(im, Input.IsNew); @@ -159,10 +159,10 @@ public class Htit : AbstractBase // Calculate period double pd = (im != 0 && re != 0) ? TWO_PI / System.Math.Atan(im / re) : 0; pd = ClampPeriod(pd, _lastPd); - pd = ALPHA * pd + BETA * _lastPd; + pd = (ALPHA * pd) + (BETA * _lastPd); _pdBuffer.Add(pd, Input.IsNew); - double sd = 0.33 * pd + 0.67 * _sdBuffer[0]; + double sd = (0.33 * pd) + (0.67 * _sdBuffer[0]); _sdBuffer.Add(sd, Input.IsNew); // Smooth dominant cycle period diff --git a/lib/averages/Hwma.cs b/lib/averages/Hwma.cs index 8927b8eb..ba97fa73 100644 --- a/lib/averages/Hwma.cs +++ b/lib/averages/Hwma.cs @@ -110,19 +110,19 @@ public class Hwma : AbstractBase [MethodImpl(MethodImplOptions.AggressiveInlining)] private double CalculateLevel(double input) { - return _oneMinusNa * (_pF + _pV + _halfA * _pA) + _nA * input; + return (_oneMinusNa * (_pF + _pV + (_halfA * _pA))) + (_nA * input); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private double CalculateVelocity(double F) { - return _oneMinusNb * (_pV + _pA) + _nB * (F - _pF); + return (_oneMinusNb * (_pV + _pA)) + (_nB * (F - _pF)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private double CalculateAcceleration(double V) { - return _oneMinusNc * _pA + _nC * (V - _pV); + return (_oneMinusNc * _pA) + (_nC * (V - _pV)); } protected override double Calculation() @@ -152,6 +152,6 @@ public class Hwma : AbstractBase _pA = A; IsHot = _index >= WarmupPeriod; - return F + V + _halfA * A; + return F + V + (_halfA * A); } } diff --git a/lib/averages/Jma.cs b/lib/averages/Jma.cs index 092e3607..9a09c2d6 100644 --- a/lib/averages/Jma.cs +++ b/lib/averages/Jma.cs @@ -61,7 +61,7 @@ public class Jma : AbstractBase _vsumBuff = new CircularBuffer(buffer); _avoltyBuff = new CircularBuffer(65); - _beta = factor * (period - 1) / (factor * (period - 1) + 2); + _beta = factor * (period - 1) / ((factor * (period - 1)) + 2); _len1 = System.Math.Max((System.Math.Log(System.Math.Sqrt(period - 1)) / System.Math.Log(2.0)) + 2.0, 0); _pow1 = System.Math.Max(_len1 - 2.0, 0.5); @@ -160,12 +160,12 @@ public class Jma : AbstractBase _lowerBand = (del2 <= 0) ? price : price - (Kv * del2); double alpha = System.Math.Pow(_beta, pow2); - double ma1 = price + alpha * (_prevMa1 - price); + double ma1 = price + (alpha * (_prevMa1 - price)); _prevMa1 = ma1; - double det0 = price + _beta * (_prevDet0 - price + ma1) - ma1; + double det0 = price + (_beta * (_prevDet0 - price + ma1)) - ma1; _prevDet0 = det0; - double ma2 = ma1 + _phase * det0; + double ma2 = ma1 + (_phase * det0); double det1 = ((ma2 - _prevJma) * _oneMinusAlphaSquared) + (_alphaSquared * _prevDet1); _prevDet1 = det1; diff --git a/lib/averages/Ltma.cs b/lib/averages/Ltma.cs index dd7c8415..8605c784 100644 --- a/lib/averages/Ltma.cs +++ b/lib/averages/Ltma.cs @@ -90,13 +90,13 @@ public class Ltma : AbstractBase [MethodImpl(MethodImplOptions.AggressiveInlining)] private double CalculateLaguerreStage(double input, double prev, double prevPrev) { - return -_gamma * input + prev + _gamma * prevPrev; + return (-_gamma * input) + prev + (_gamma * prevPrev); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private double CombineOutputs(double l0, double l1, double l2, double l3) { - return (l0 + 2.0 * (l1 + l2) + l3) * _invSix; + return (l0 + (2.0 * (l1 + l2)) + l3) * _invSix; } protected override double Calculation() @@ -104,7 +104,7 @@ public class Ltma : AbstractBase ManageState(Input.IsNew); // First stage - double l0 = _oneMinusGamma * Input.Value + _gamma * _prevL0; + double l0 = (_oneMinusGamma * Input.Value) + (_gamma * _prevL0); // Subsequent stages using helper method double l1 = CalculateLaguerreStage(l0, _prevL0, _prevL1); diff --git a/lib/averages/Maaf.cs b/lib/averages/Maaf.cs index 11c0fb81..c2340eb3 100644 --- a/lib/averages/Maaf.cs +++ b/lib/averages/Maaf.cs @@ -93,7 +93,7 @@ public class Maaf : AbstractBase [MethodImpl(MethodImplOptions.AggressiveInlining)] private double CalculateSmooth() { - return (_priceBuffer[^1] + 2.0 * (_priceBuffer[^2] + _priceBuffer[^3]) + _priceBuffer[^4]) * _invSix; + return (_priceBuffer[^1] + (2.0 * (_priceBuffer[^2] + _priceBuffer[^3])) + _priceBuffer[^4]) * _invSix; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -141,7 +141,7 @@ public class Maaf : AbstractBase { double alpha = CalculateAlpha(length); double value1 = GetMedian(length); - value2 = alpha * (smooth - _prevValue2) + _prevValue2; + value2 = (alpha * (smooth - _prevValue2)) + _prevValue2; if (value1 != 0) { @@ -153,7 +153,7 @@ public class Maaf : AbstractBase length = System.Math.Max(length, 3); double finalAlpha = CalculateAlpha(length); - double filter = finalAlpha * (smooth - _prevFilter) + _prevFilter; + double filter = (finalAlpha * (smooth - _prevFilter)) + _prevFilter; _prevFilter = filter; _prevValue2 = value2; diff --git a/lib/averages/Mama.cs b/lib/averages/Mama.cs index 3722ab90..a87a46e1 100644 --- a/lib/averages/Mama.cs +++ b/lib/averages/Mama.cs @@ -100,13 +100,13 @@ public class Mama : AbstractBase [MethodImpl(MethodImplOptions.AggressiveInlining)] private double CalculateSmooth() { - return (4.0 * _pr[^1] + 3.0 * _pr[^2] + 2.0 * _pr[^3] + _pr[^4]) * 0.1; + return ((4.0 * _pr[^1]) + (3.0 * _pr[^2]) + (2.0 * _pr[^3]) + _pr[^4]) * 0.1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static double CalculateHilbertTransform(CircularBuffer buffer, double adj) { - return (0.0962 * (buffer[^1] - buffer[^7]) + 0.5769 * (buffer[^3] - buffer[^5])) * adj; + return ((0.0962 * (buffer[^1] - buffer[^7])) + (0.5769 * (buffer[^3] - buffer[^5]))) * adj; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -121,7 +121,7 @@ public class Mama : AbstractBase { period = System.Math.Clamp(period, 0.67 * _pd[^2], 1.5 * _pd[^2]); period = System.Math.Clamp(period, 6.0, 50.0); - return _alpha02 * period + _alpha08 * _pd[^2]; + return (_alpha02 * period) + (_alpha08 * _pd[^2]); } protected override double Calculation() @@ -132,7 +132,7 @@ public class Mama : AbstractBase if (_index > 6) { - double adj = 0.075 * _pd[^1] + 0.54; + double adj = (0.075 * _pd[^1]) + 0.54; // Smooth and Detrender _sm.Add(CalculateSmooth(), Input.IsNew); @@ -151,16 +151,16 @@ public class Mama : AbstractBase double q2 = _q1[^1] + jI; _i2.Add(i2, Input.IsNew); _q2.Add(q2, Input.IsNew); - _i2[^1] = _alpha02 * _i2[^1] + _alpha08 * _i2[^2]; - _q2[^1] = _alpha02 * _q2[^1] + _alpha08 * _q2[^2]; + _i2[^1] = (_alpha02 * _i2[^1]) + (_alpha08 * _i2[^2]); + _q2[^1] = (_alpha02 * _q2[^1]) + (_alpha08 * _q2[^2]); // Homodyne discriminator - double re = _i2[^1] * _i2[^2] + _q2[^1] * _q2[^2]; - double im = _i2[^1] * _q2[^2] - _q2[^1] * _i2[^2]; + double re = (_i2[^1] * _i2[^2]) + (_q2[^1] * _q2[^2]); + double im = (_i2[^1] * _q2[^2]) - (_q2[^1] * _i2[^2]); _re.Add(re, Input.IsNew); _im.Add(im, Input.IsNew); - _re[^1] = _alpha02 * _re[^1] + _alpha08 * _re[^2]; - _im[^1] = _alpha02 * _im[^1] + _alpha08 * _im[^2]; + _re[^1] = (_alpha02 * _re[^1]) + (_alpha08 * _re[^2]); + _im[^1] = (_alpha02 * _im[^1]) + (_alpha08 * _im[^2]); // Calculate and adjust period double period = CalculatePeriod(_im[^1], _re[^1]); @@ -176,8 +176,8 @@ public class Mama : AbstractBase double alpha = System.Math.Clamp(_fastLimit / delta, _slowLimit, _fastLimit); // Final indicators - _mama = alpha * (_pr[^1] - _prevMama) + _prevMama; - _fama = _famaAlpha * alpha * (_mama - _prevFama) + _prevFama; + _mama = (alpha * (_pr[^1] - _prevMama)) + _prevMama; + _fama = (_famaAlpha * alpha * (_mama - _prevFama)) + _prevFama; _prevMama = _mama; _prevFama = _fama; diff --git a/lib/averages/Mma.cs b/lib/averages/Mma.cs index c999ee09..0f505408 100644 --- a/lib/averages/Mma.cs +++ b/lib/averages/Mma.cs @@ -51,7 +51,7 @@ public class Mma : AbstractBase _weights = new double[period]; for (int i = 0; i < period; i++) { - _weights[i] = (period - (2 * i + 1)) * 0.5; + _weights[i] = (period - ((2 * i) + 1)) * 0.5; } Name = "Mma"; diff --git a/lib/averages/Qema.cs b/lib/averages/Qema.cs index 66cc7107..9bcd0ec6 100644 --- a/lib/averages/Qema.cs +++ b/lib/averages/Qema.cs @@ -107,7 +107,7 @@ public class Qema : AbstractBase double ema4 = CalculateEma(_ema4, ema3); // Combine EMAs using optimized formula - _lastQema = 4.0 * (ema1 + ema3) - (6.0 * ema2 + ema4); + _lastQema = (4.0 * (ema1 + ema3)) - ((6.0 * ema2) + ema4); IsHot = _index >= WarmupPeriod; return _lastQema; diff --git a/lib/averages/Rema.cs b/lib/averages/Rema.cs index 65c76f70..177986bf 100644 --- a/lib/averages/Rema.cs +++ b/lib/averages/Rema.cs @@ -105,9 +105,9 @@ public class Rema : AbstractBase [MethodImpl(MethodImplOptions.AggressiveInlining)] private double CalculateRema(double alpha, double input) { - double standardTerm = _lastRema + alpha * (input - _lastRema); + double standardTerm = _lastRema + (alpha * (input - _lastRema)); double regularizationTerm = _lastRema + (_lastRema - _prevRema); - return (standardTerm + _lambda * regularizationTerm) * _lambdaPlus1Recip; + return (standardTerm + (_lambda * regularizationTerm)) * _lambdaPlus1Recip; } protected override double Calculation() diff --git a/lib/averages/Rma.cs b/lib/averages/Rma.cs index 71dc6a76..16c92029 100644 --- a/lib/averages/Rma.cs +++ b/lib/averages/Rma.cs @@ -98,7 +98,7 @@ public class Rma : AbstractBase [MethodImpl(MethodImplOptions.AggressiveInlining)] private double CalculateRma(double input) { - return _k * input + _oneMinusK * _lastRma; + return (_k * input) + (_oneMinusK * _lastRma); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/lib/averages/Smma.cs b/lib/averages/Smma.cs index a508acff..0cb983e7 100644 --- a/lib/averages/Smma.cs +++ b/lib/averages/Smma.cs @@ -84,7 +84,7 @@ public class Smma : AbstractBase [MethodImpl(MethodImplOptions.AggressiveInlining)] private double CalculateSmma(double input) { - return (_lastSmma * _periodMinusOne + input) * _periodRecip; + return ((_lastSmma * _periodMinusOne) + input) * _periodRecip; } protected override double Calculation() diff --git a/lib/averages/T3.cs b/lib/averages/T3.cs index f0d3402f..197d1eca 100644 --- a/lib/averages/T3.cs +++ b/lib/averages/T3.cs @@ -60,8 +60,8 @@ public class T3 : AbstractBase double v3 = v2 * vfactor; _c1 = -v3; _c2 = 3.0 * (v2 + v3); - _c3 = -3.0 * (2.0 * v2 + vfactor + v3); - _c4 = 1.0 + 3.0 * vfactor + v3 + 3.0 * v2; + _c3 = -3.0 * ((2.0 * v2) + vfactor + v3); + _c4 = 1.0 + (3.0 * vfactor) + v3 + (3.0 * v2); _buffer1 = new(period); _buffer2 = new(period); @@ -124,13 +124,13 @@ public class T3 : AbstractBase [MethodImpl(MethodImplOptions.AggressiveInlining)] private double CalculateEma(double input, double lastEma) { - return _k * (input - lastEma) + lastEma; + return (_k * (input - lastEma)) + lastEma; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private double CalculateT3(double ema3, double ema4, double ema5, double ema6) { - return _c1 * ema6 + _c2 * ema5 + _c3 * ema4 + _c4 * ema3; + return (_c1 * ema6) + (_c2 * ema5) + (_c3 * ema4) + (_c4 * ema3); } protected override double Calculation() diff --git a/lib/averages/Tema.cs b/lib/averages/Tema.cs index ac85723c..b10f9191 100644 --- a/lib/averages/Tema.cs +++ b/lib/averages/Tema.cs @@ -93,7 +93,7 @@ public class Tema : AbstractBase [MethodImpl(MethodImplOptions.AggressiveInlining)] private double CalculateEma(double input, double lastEma, double invE) { - return _k * (input * invE - lastEma) + lastEma; + return (_k * ((input * invE) - lastEma)) + lastEma; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -120,7 +120,7 @@ public class Tema : AbstractBase _lastEma3 = ema3; // Calculate final TEMA with compensation - double result = (3.0 * ema1 - 3.0 * ema2 + ema3) * invE; + double result = ((3.0 * ema1) - (3.0 * ema2) + ema3) * invE; IsHot = _index >= WarmupPeriod; return result; diff --git a/lib/averages/Zlema.cs b/lib/averages/Zlema.cs index cb339950..ebefa84f 100644 --- a/lib/averages/Zlema.cs +++ b/lib/averages/Zlema.cs @@ -86,7 +86,7 @@ public class Zlema : AbstractBase private double CalculateErrorCorrection() { double lagValue = _buffer[System.Math.Max(0, _buffer.Count - 1 - _lag)]; - return 2.0 * Input.Value - lagValue; + return (2.0 * Input.Value) - lagValue; } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/lib/feeds/GbmFeed.cs b/lib/feeds/GbmFeed.cs index 566ee8db..fcaa2ae8 100644 --- a/lib/feeds/GbmFeed.cs +++ b/lib/feeds/GbmFeed.cs @@ -32,7 +32,7 @@ public class GbmFeed : TBarSeries public TBar Generate(DateTime time, bool isNew = true) { double dt = 1.0 / 252; - double drift = (_mu - 0.5 * _sigma * _sigma) * dt; + double drift = (_mu - (0.5 * _sigma * _sigma)) * dt; double diffusion = _sigma * Math.Sqrt(dt) * GenerateNormalRandom(); double open = _lastClose; @@ -40,8 +40,8 @@ public class GbmFeed : TBarSeries // Generate intra-bar price movements double maxMove = Math.Abs(close - open) * 1.5; // Allow for some extra movement within the bar - double high = Math.Max(open, close) + maxMove * GenerateRandomDouble(); - double low = Math.Min(open, close) - maxMove * GenerateRandomDouble(); + double high = Math.Max(open, close) + (maxMove * GenerateRandomDouble()); + double low = Math.Min(open, close) - (maxMove * GenerateRandomDouble()); // Ensure high is always greater than or equal to both open and close high = Math.Max(high, Math.Max(open, close)); @@ -49,7 +49,7 @@ public class GbmFeed : TBarSeries // Ensure low is always less than or equal to both open and close low = Math.Min(low, Math.Min(open, close)); - double volume = 1000 + GenerateRandomDouble() * 1000; + double volume = 1000 + (GenerateRandomDouble() * 1000); if (isNew) { diff --git a/lib/momentum/Dpo.cs b/lib/momentum/Dpo.cs index f88ad083..6a7b084a 100644 --- a/lib/momentum/Dpo.cs +++ b/lib/momentum/Dpo.cs @@ -46,7 +46,7 @@ public sealed class Dpo : AbstractBase [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dpo(int period = 20) { - _shift = period / 2 + 1; + _shift = (period / 2) + 1; WarmupPeriod = period + _shift; Name = $"DPO({period})"; _prices = new CircularBuffer(WarmupPeriod); diff --git a/lib/oscillators/Cfo.cs b/lib/oscillators/Cfo.cs index d2693a36..5921aeaf 100644 --- a/lib/oscillators/Cfo.cs +++ b/lib/oscillators/Cfo.cs @@ -86,11 +86,11 @@ public sealed class Cfo : AbstractBase var n = (double)count; // Calculate linear regression coefficients - var slope = (n * _sumXY - _sumX * _sumY) / (n * _sumX2 - _sumX * _sumX); - var intercept = (_sumY - slope * _sumX) / n; + var slope = ((n * _sumXY) - (_sumX * _sumY)) / ((n * _sumX2) - (_sumX * _sumX)); + var intercept = (_sumY - (slope * _sumX)) / n; // Calculate forecast for next period - return intercept + slope * count; + return intercept + (slope * count); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/lib/oscillators/Cog.cs b/lib/oscillators/Cog.cs index 0c9aec23..6e49e647 100644 --- a/lib/oscillators/Cog.cs +++ b/lib/oscillators/Cog.cs @@ -96,6 +96,6 @@ public sealed class Cog : AbstractBase return 0.0; // Calculate center of gravity and normalize - return -((numerator / denominator) - (_period + 1.0) / 2.0); + return -((numerator / denominator) - ((_period + 1.0) / 2.0)); } } diff --git a/lib/statistics/Curvature.cs b/lib/statistics/Curvature.cs index 157b5fd6..76249a10 100644 --- a/lib/statistics/Curvature.cs +++ b/lib/statistics/Curvature.cs @@ -74,7 +74,7 @@ public sealed class Curvature : AbstractBase "Period must be greater than 2 for Curvature calculation."); } _period = period; - WarmupPeriod = period * 2 - 1; // Number of points needed for period number of slopes + WarmupPeriod = (period * 2) - 1; // Number of points needed for period number of slopes _slopeCalculator = new Slope(period); _slopeBuffer = new CircularBuffer(period); Name = $"Curvature(period={period})"; diff --git a/lib/statistics/Kurtosis.cs b/lib/statistics/Kurtosis.cs index 023cae36..c0d76a25 100644 --- a/lib/statistics/Kurtosis.cs +++ b/lib/statistics/Kurtosis.cs @@ -129,7 +129,7 @@ public sealed class Kurtosis : AbstractBase if (variance2 < Epsilon) return 0; - return (n * (n + 1) * s4) / (variance2 * (n - 3) * (n - 1) * (n - 2)) + return ((n * (n + 1) * s4) / (variance2 * (n - 3) * (n - 1) * (n - 2))) - (3 * (n - 1) * (n - 1) / ((n - 2) * (n - 3))); } diff --git a/lib/statistics/Percentile.cs b/lib/statistics/Percentile.cs index 4617cdc0..611768ca 100644 --- a/lib/statistics/Percentile.cs +++ b/lib/statistics/Percentile.cs @@ -148,7 +148,7 @@ public sealed class Percentile : AbstractBase double lowerValue = sortedValues[lowerIndex]; double upperValue = sortedValues[upperIndex]; double fraction = position - lowerIndex; - return lowerValue + (upperValue - lowerValue) * fraction; + return lowerValue + ((upperValue - lowerValue) * fraction); } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] diff --git a/lib/volatility/Ap.cs b/lib/volatility/Ap.cs index 5ce827fb..803cc83c 100644 --- a/lib/volatility/Ap.cs +++ b/lib/volatility/Ap.cs @@ -115,6 +115,6 @@ public sealed class Ap : AbstractBase // Project median line to current bar double currentX = _index - p0.x; - return p0.y + slope * currentX; + return p0.y + (slope * currentX); } } diff --git a/lib/volatility/Jvolty.cs b/lib/volatility/Jvolty.cs index ffac4d58..97c436f4 100644 --- a/lib/volatility/Jvolty.cs +++ b/lib/volatility/Jvolty.cs @@ -83,7 +83,7 @@ public sealed class Jvolty : AbstractBase _vsumBuff = new CircularBuffer(VsumBufferSize); _avoltyBuff = new CircularBuffer(AvoltyBufferSize); - _beta = 0.45 * (period - 1) / (0.45 * (period - 1) + 2); + _beta = 0.45 * (period - 1) / ((0.45 * (period - 1)) + 2); WarmupPeriod = period * 2; Name = $"JVOLTY({period})"; @@ -155,9 +155,9 @@ public sealed class Jvolty : AbstractBase [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] private double CalculateJma(double price, double alpha, double ma1) { - double det0 = (price - ma1) * (1 - _beta) + _beta * _prevDet0; + double det0 = ((price - ma1) * (1 - _beta)) + (_beta * _prevDet0); _prevDet0 = det0; - double ma2 = ma1 + _phase * det0; + double ma2 = ma1 + (_phase * det0); double det1 = ((ma2 - _prevJma) * (1 - alpha) * (1 - alpha)) + (alpha * alpha * _prevDet1); _prevDet1 = det1; @@ -200,7 +200,7 @@ public sealed class Jvolty : AbstractBase // Apply JMA smoothing double alpha = Math.Pow(_beta, pow2); - double ma1 = (1 - alpha) * price + alpha * _prevMa1; + double ma1 = ((1 - alpha) * price) + (alpha * _prevMa1); _prevMa1 = ma1; double jma = CalculateJma(price, alpha, ma1); diff --git a/quantower/Statistics/CurvatureIndicator.cs b/quantower/Statistics/CurvatureIndicator.cs index 4ba48c9e..2180cd61 100644 --- a/quantower/Statistics/CurvatureIndicator.cs +++ b/quantower/Statistics/CurvatureIndicator.cs @@ -26,7 +26,7 @@ public class CurvatureIndicator : Indicator, IWatchlistIndicator protected LineSeries? CurvatureSeries; protected LineSeries? LineSeries; protected string? SourceName; - public int MinHistoryDepths => Periods * 2 - 1; + public int MinHistoryDepths => (Periods * 2) - 1; int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths; public CurvatureIndicator()