mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-21 03:58:04 +00:00
[CodeFactor] Apply fixes
This commit is contained in:
@@ -486,8 +486,8 @@ public class SyntheticVendor : Vendor
|
|||||||
|
|
||||||
// Calculate the sine wave values
|
// Calculate the sine wave values
|
||||||
double frequency = 2 * Math.PI / 1500; // Complete cycle over 25 hours
|
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 value = 50 + (50 * Math.Sin(cyclePosition * frequency)); // Oscillate between 0 and 100
|
||||||
double nextValue = 50 + 50 * Math.Sin((cyclePosition + slice.TotalMinutes) * frequency);
|
double nextValue = 50 + (50 * Math.Sin((cyclePosition + slice.TotalMinutes) * frequency));
|
||||||
|
|
||||||
double factor = 0.6 * Math.Abs(nextValue - value);
|
double factor = 0.6 * Math.Abs(nextValue - value);
|
||||||
|
|
||||||
@@ -537,7 +537,7 @@ public class SyntheticVendor : Vendor
|
|||||||
openValue = 100;
|
openValue = 100;
|
||||||
closeValue = 0.0001;
|
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
|
// Transition from 0 to 100 at midnight
|
||||||
openValue = 0.0001;
|
openValue = 0.0001;
|
||||||
@@ -566,8 +566,8 @@ public class SyntheticVendor : Vendor
|
|||||||
double hours = (time - DateTime.UnixEpoch).TotalHours;
|
double hours = (time - DateTime.UnixEpoch).TotalHours;
|
||||||
double period = 24; // 24-hour period
|
double period = 24; // 24-hour period
|
||||||
double position = hours % period;
|
double position = hours % period;
|
||||||
double value = 200 * (position / period) - 100;
|
double value = (200 * (position / period)) - 100;
|
||||||
double nextValue = 200 * ((position + slice.TotalHours) % period / period) - 100;
|
double nextValue = (200 * (((position + slice.TotalHours) % period) / period)) - 100;
|
||||||
|
|
||||||
return new HistoryItemBar
|
return new HistoryItemBar
|
||||||
{
|
{
|
||||||
@@ -588,7 +588,7 @@ public class SyntheticVendor : Vendor
|
|||||||
double period = 24; // 24-hour period
|
double period = 24; // 24-hour period
|
||||||
double position = hours % period;
|
double position = hours % period;
|
||||||
double value = 100 - (200 * (position / 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
|
return new HistoryItemBar
|
||||||
{
|
{
|
||||||
@@ -628,8 +628,8 @@ public class SyntheticVendor : Vendor
|
|||||||
double hours = (time - DateTime.UnixEpoch).TotalHours;
|
double hours = (time - DateTime.UnixEpoch).TotalHours;
|
||||||
double period = 24;
|
double period = 24;
|
||||||
double position = hours % period;
|
double position = hours % period;
|
||||||
double value = 200 * (Math.Abs(position / 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;
|
double nextValue = 200 * (Math.Abs((((position + slice.TotalHours) % period) / period) - 0.5) - 0.25) * 100;
|
||||||
|
|
||||||
return new HistoryItemBar
|
return new HistoryItemBar
|
||||||
{
|
{
|
||||||
@@ -651,7 +651,7 @@ public class SyntheticVendor : Vendor
|
|||||||
double frequency = 2 * Math.PI / period; // Full cycle over 24 hours
|
double frequency = 2 * Math.PI / period; // Full cycle over 24 hours
|
||||||
|
|
||||||
// Adjust time to center the main peak at 12 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
|
// Scale factor
|
||||||
double scaleFactor = 7.0;
|
double scaleFactor = 7.0;
|
||||||
@@ -661,7 +661,7 @@ public class SyntheticVendor : Vendor
|
|||||||
double sincValue = x != 0 ? 100 * Math.Sin(x) / x : 100;
|
double sincValue = x != 0 ? 100 * Math.Sin(x) / x : 100;
|
||||||
|
|
||||||
// Calculate next value
|
// 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 nextX = scaleFactor * frequency * nextT;
|
||||||
double nextSincValue = nextX != 0 ? 100 * Math.Sin(nextX) / nextX : 100;
|
double nextSincValue = nextX != 0 ? 100 * Math.Sin(nextX) / nextX : 100;
|
||||||
|
|
||||||
@@ -701,7 +701,7 @@ public class SyntheticVendor : Vendor
|
|||||||
double value;
|
double value;
|
||||||
if (position < pulsePeriod)
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -713,7 +713,7 @@ public class SyntheticVendor : Vendor
|
|||||||
double nextValue;
|
double nextValue;
|
||||||
if (nextPosition < pulsePeriod)
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -875,9 +875,9 @@ public class SyntheticVendor : Vendor
|
|||||||
double meanReversionStrength = 0.1;
|
double meanReversionStrength = 0.1;
|
||||||
|
|
||||||
double openNoise = random.NextDouble();
|
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 closeNoise = random.NextDouble();
|
||||||
double close = open + volatility * closeNoise + meanReversionStrength * (meanPrice - open);
|
double close = open + (volatility * closeNoise) + (meanReversionStrength * (meanPrice - open));
|
||||||
|
|
||||||
// Determine High and Low
|
// Determine High and Low
|
||||||
double high = Math.Max(open, close);
|
double high = Math.Max(open, close);
|
||||||
@@ -890,7 +890,7 @@ public class SyntheticVendor : Vendor
|
|||||||
double lowNoise = Math.Abs(random.NextDouble());
|
double lowNoise = Math.Abs(random.NextDouble());
|
||||||
low -= volatility * lowNoise;
|
low -= volatility * lowNoise;
|
||||||
|
|
||||||
double volume = Math.Abs(random.NextDouble()) * 1000 + 100;
|
double volume = (Math.Abs(random.NextDouble()) * 1000) + 100;
|
||||||
|
|
||||||
previousClose = close;
|
previousClose = close;
|
||||||
|
|
||||||
@@ -923,11 +923,11 @@ public class SyntheticVendor : Vendor
|
|||||||
|
|
||||||
// Generate open price
|
// Generate open price
|
||||||
double openNoise = GeneratePinkNoiseValue();
|
double openNoise = GeneratePinkNoiseValue();
|
||||||
double open = previousClose + volatility * openNoise + meanReversionStrength * (meanPrice - previousClose);
|
double open = previousClose + (volatility * openNoise) + (meanReversionStrength * (meanPrice - previousClose));
|
||||||
|
|
||||||
// Generate close price
|
// Generate close price
|
||||||
double closeNoise = GeneratePinkNoiseValue();
|
double closeNoise = GeneratePinkNoiseValue();
|
||||||
double close = open + volatility * closeNoise + meanReversionStrength * (meanPrice - open);
|
double close = open + (volatility * closeNoise) + (meanReversionStrength * (meanPrice - open));
|
||||||
|
|
||||||
// Determine High and Low
|
// Determine High and Low
|
||||||
double high = Math.Max(open, close);
|
double high = Math.Max(open, close);
|
||||||
@@ -940,7 +940,7 @@ public class SyntheticVendor : Vendor
|
|||||||
double lowNoise = Math.Abs(GeneratePinkNoiseValue());
|
double lowNoise = Math.Abs(GeneratePinkNoiseValue());
|
||||||
low -= volatility * lowNoise;
|
low -= volatility * lowNoise;
|
||||||
|
|
||||||
double volume = Math.Abs(GeneratePinkNoiseValue()) * 1000 + 100;
|
double volume = (Math.Abs(GeneratePinkNoiseValue()) * 1000) + 100;
|
||||||
|
|
||||||
// Update previous close for the next iteration
|
// Update previous close for the next iteration
|
||||||
previousClose = close;
|
previousClose = close;
|
||||||
@@ -967,7 +967,7 @@ public class SyntheticVendor : Vendor
|
|||||||
|
|
||||||
for (int i = 0; i < NumOctaves; i++)
|
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;
|
pinkNoiseState[i] = (pinkNoiseState[i] + white) * 0.5;
|
||||||
total += pinkNoiseState[i] * Math.Pow(2, -i);
|
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 u1 = 1.0 - random.NextDouble(); // Uniform(0,1] random doubles
|
||||||
double u2 = 1.0 - random.NextDouble();
|
double u2 = 1.0 - random.NextDouble();
|
||||||
double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2);
|
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);
|
double epsilon = GenerateGaussian(0, 1);
|
||||||
|
|
||||||
// Calculate the price movement using GBM equation
|
// 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 diffusion = GBMSigma * Math.Sqrt(dt) * epsilon;
|
||||||
double returnValue = Math.Exp(drift + diffusion);
|
double returnValue = Math.Exp(drift + diffusion);
|
||||||
|
|
||||||
@@ -1046,11 +1046,11 @@ public class SyntheticVendor : Vendor
|
|||||||
|
|
||||||
// Generate High and Low values
|
// Generate High and Low values
|
||||||
double highLowRange = Math.Max(Math.Abs(close - open), GBMLastClose * GBMSigma * Math.Sqrt(dt) * Math.Abs(GenerateGaussian(0, 1)));
|
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 high = Math.Max(open, close) + (highLowRange * 0.5);
|
||||||
double low = Math.Min(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)
|
// 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
|
// Update last close for next iteration
|
||||||
GBMLastClose = close;
|
GBMLastClose = close;
|
||||||
@@ -1089,11 +1089,11 @@ public class SyntheticVendor : Vendor
|
|||||||
|
|
||||||
double highLowRange = Math.Max(Math.Abs(close - open),
|
double highLowRange = Math.Max(Math.Abs(close - open),
|
||||||
FBMLastClose * FBMSigma * Math.Pow(dt, FBMHurst) * Math.Abs(GenerateFractionalGaussianNoise(FBMHurst)) * 2);
|
FBMLastClose * FBMSigma * Math.Pow(dt, FBMHurst) * Math.Abs(GenerateFractionalGaussianNoise(FBMHurst)) * 2);
|
||||||
double high = Math.Max(open, close) + highLowRange * 0.5;
|
double high = Math.Max(open, close) + (highLowRange * 0.5);
|
||||||
double low = Math.Min(open, close) - highLowRange * 0.5;
|
double low = Math.Min(open, close) - (highLowRange * 0.5);
|
||||||
|
|
||||||
double volume = Math.Max(100, 2000 * Math.Abs(close - open) +
|
double volume = Math.Max(100, (2000 * Math.Abs(close - open)) +
|
||||||
1000 * Math.Abs(GenerateFractionalGaussianNoise(FBMHurst)));
|
(1000 * Math.Abs(GenerateFractionalGaussianNoise(FBMHurst))));
|
||||||
|
|
||||||
FBMLastClose = close;
|
FBMLastClose = close;
|
||||||
|
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ public class EventingTests
|
|||||||
randomValue,
|
randomValue,
|
||||||
randomValue + Math.Abs(GetRandomDouble(rng) * 10),
|
randomValue + Math.Abs(GetRandomDouble(rng) * 10),
|
||||||
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),
|
Math.Abs(GetRandomDouble(rng) * 1000),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|||||||
+4
-4
@@ -125,10 +125,10 @@ public class BarIndicatorTests
|
|||||||
/// <returns>A randomly generated TBar.</returns>
|
/// <returns>A randomly generated TBar.</returns>
|
||||||
private TBar GenerateRandomBar(bool isNew)
|
private TBar GenerateRandomBar(bool isNew)
|
||||||
{
|
{
|
||||||
double open = GetRandomDouble() * 200 - 100;
|
double open = (GetRandomDouble() * 200) - 100;
|
||||||
double close = GetRandomDouble() * 200 - 100;
|
double close = (GetRandomDouble() * 200) - 100;
|
||||||
double high = Math.Max(open, close) + GetRandomDouble() * 10;
|
double high = Math.Max(open, close) + (GetRandomDouble() * 10);
|
||||||
double low = Math.Min(open, close) - GetRandomDouble() * 10;
|
double low = Math.Min(open, close) - (GetRandomDouble() * 10);
|
||||||
long volume = GetRandomNumber(0, 10000);
|
long volume = GetRandomNumber(0, 10000);
|
||||||
|
|
||||||
return new TBar(Time: DateTime.Now, Open: open, High: high, Low: low, Close: close, Volume: volume, IsNew: isNew);
|
return new TBar(Time: DateTime.Now, Open: open, High: high, Low: low, Close: close, Volume: volume, IsNew: isNew);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class AveragesUpdateTests
|
|||||||
{
|
{
|
||||||
byte[] bytes = new byte[8];
|
byte[] bytes = new byte[8];
|
||||||
rng.GetBytes(bytes);
|
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]
|
[Fact]
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class UpdateTests
|
|||||||
{
|
{
|
||||||
byte[] bytes = new byte[8];
|
byte[] bytes = new byte[8];
|
||||||
rng.GetBytes(bytes);
|
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]
|
[Fact]
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class MomentumUpdateTests
|
|||||||
{
|
{
|
||||||
byte[] bytes = new byte[8];
|
byte[] bytes = new byte[8];
|
||||||
rng.GetBytes(bytes);
|
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)
|
private TBar GetRandomBar(bool IsNew)
|
||||||
@@ -22,7 +22,7 @@ public class MomentumUpdateTests
|
|||||||
double open = GetRandomDouble();
|
double open = GetRandomDouble();
|
||||||
double high = open + Math.Abs(GetRandomDouble());
|
double high = open + Math.Abs(GetRandomDouble());
|
||||||
double low = 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);
|
return new TBar(DateTime.Now, open, high, low, close, 1000, IsNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class OscillatorsUpdateTests
|
|||||||
{
|
{
|
||||||
byte[] bytes = new byte[8];
|
byte[] bytes = new byte[8];
|
||||||
rng.GetBytes(bytes);
|
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]
|
[Fact]
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class StatisticsUpdateTests
|
|||||||
{
|
{
|
||||||
byte[] bytes = new byte[8];
|
byte[] bytes = new byte[8];
|
||||||
rng.GetBytes(bytes);
|
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]
|
[Fact]
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class VolatilityUpdateTests
|
|||||||
{
|
{
|
||||||
byte[] bytes = new byte[8];
|
byte[] bytes = new byte[8];
|
||||||
rng.GetBytes(bytes);
|
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)
|
private TBar GetRandomBar(bool IsNew)
|
||||||
@@ -22,7 +22,7 @@ public class VolatilityUpdateTests
|
|||||||
double open = GetRandomDouble();
|
double open = GetRandomDouble();
|
||||||
double high = open + Math.Abs(GetRandomDouble());
|
double high = open + Math.Abs(GetRandomDouble());
|
||||||
double low = 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);
|
return new TBar(DateTime.Now, open, high, low, close, 1000, IsNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class VolumeUpdateTests
|
|||||||
{
|
{
|
||||||
byte[] bytes = new byte[8];
|
byte[] bytes = new byte[8];
|
||||||
rng.GetBytes(bytes);
|
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)
|
private TBar GetRandomBar(bool IsNew)
|
||||||
@@ -21,7 +21,7 @@ public class VolumeUpdateTests
|
|||||||
double open = GetRandomDouble();
|
double open = GetRandomDouble();
|
||||||
double high = open + Math.Abs(GetRandomDouble());
|
double high = open + Math.Abs(GetRandomDouble());
|
||||||
double low = 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
|
double volume = Math.Abs(GetRandomDouble()) * 1000; // Random positive volume
|
||||||
return new TBar(DateTime.Now, open, high, low, close, volume, IsNew);
|
return new TBar(DateTime.Now, open, high, low, close, volume, IsNew);
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-16
@@ -60,12 +60,12 @@ public class Afirma : AbstractBase
|
|||||||
_n = (Taps - 1) / 2;
|
_n = (Taps - 1) / 2;
|
||||||
|
|
||||||
// Precalculate least squares coefficients
|
// Precalculate least squares coefficients
|
||||||
_sx2 = (2 * _n + 1) / 3.0;
|
_sx2 = ((2 * _n) + 1) / 3.0;
|
||||||
_sx3 = _n * (_n + 1) / 2.0;
|
_sx3 = _n * (_n + 1) / 2.0;
|
||||||
_sx4 = _sx2 * (3 * _n * _n + 3 * _n - 1) / 5.0;
|
_sx4 = _sx2 * ((3 * _n * _n) + (3 * _n) - 1) / 5.0;
|
||||||
_sx5 = _sx3 * (2 * _n * _n + 2 * _n - 1) / 3.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;
|
_sx6 = _sx2 * ((3 * Math.Pow(_n, 3) * (_n + 2)) - (3 * _n) + 1) / 7.0;
|
||||||
_den = _sx6 * _sx4 / _sx5 - _sx5;
|
_den = (_sx6 * _sx4 / _sx5) - _sx5;
|
||||||
|
|
||||||
Name = "Afirma";
|
Name = "Afirma";
|
||||||
Init();
|
Init();
|
||||||
@@ -105,15 +105,15 @@ public class Afirma : AbstractBase
|
|||||||
case WindowType.Rectangular:
|
case WindowType.Rectangular:
|
||||||
return 1.0;
|
return 1.0;
|
||||||
case WindowType.Hanning1:
|
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:
|
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:
|
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:
|
case WindowType.BlackmanHarris:
|
||||||
return 0.35875 - 0.48829 * Math.Cos(_twoPi * k / tapsMinusOne) +
|
return 0.35875 - (0.48829 * Math.Cos(_twoPi * k / tapsMinusOne)) +
|
||||||
0.14128 * Math.Cos(_fourPi * k / tapsMinusOne) -
|
(0.14128 * Math.Cos(_fourPi * k / tapsMinusOne)) -
|
||||||
0.01168 * Math.Cos(_sixPi * k / tapsMinusOne);
|
(0.01168 * Math.Cos(_sixPi * k / tapsMinusOne));
|
||||||
default:
|
default:
|
||||||
return 1.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
@@ -156,15 +156,15 @@ public class Afirma : AbstractBase
|
|||||||
|
|
||||||
sx2y = 2.0 * sx2y / _n / (_n + 1);
|
sx2y = 2.0 * sx2y / _n / (_n + 1);
|
||||||
sx3y = 2.0 * sx3y / _n / (_n + 1);
|
sx3y = 2.0 * sx3y / _n / (_n + 1);
|
||||||
double p = sx2y - a0 * _sx2 - a1 * _sx3;
|
double p = sx2y - (a0 * _sx2) - (a1 * _sx3);
|
||||||
double q = sx3y - a0 * _sx3 - a1 * _sx4;
|
double q = sx3y - (a0 * _sx3) - (a1 * _sx4);
|
||||||
double a2 = (p * _sx6 / _sx5 - q) / _den;
|
double a2 = ((p * _sx6 / _sx5) - q) / _den;
|
||||||
double a3 = (q * _sx4 / _sx5 - p) / _den;
|
double a3 = ((q * _sx4 / _sx5) - p) / _den;
|
||||||
|
|
||||||
for (int k = 0; k <= _n; k++)
|
for (int k = 0; k <= _n; k++)
|
||||||
{
|
{
|
||||||
double k2 = k * 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -123,10 +123,10 @@ public class Convolution : AbstractBase
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
while (i <= offset - 3)
|
while (i <= offset - 3)
|
||||||
{
|
{
|
||||||
sum += bufferSpan[offset - i] * _normalizedKernel[i] +
|
sum += (bufferSpan[offset - i] * _normalizedKernel[i]) +
|
||||||
bufferSpan[offset - (i + 1)] * _normalizedKernel[i + 1] +
|
(bufferSpan[offset - (i + 1)] * _normalizedKernel[i + 1]) +
|
||||||
bufferSpan[offset - (i + 2)] * _normalizedKernel[i + 2] +
|
(bufferSpan[offset - (i + 2)] * _normalizedKernel[i + 2]) +
|
||||||
bufferSpan[offset - (i + 3)] * _normalizedKernel[i + 3];
|
(bufferSpan[offset - (i + 3)] * _normalizedKernel[i + 3]);
|
||||||
i += 4;
|
i += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public class Dema : AbstractBase
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private double CalculateEma(double input, double lastEma)
|
private double CalculateEma(double input, double lastEma)
|
||||||
{
|
{
|
||||||
return _k * (input - lastEma) + lastEma;
|
return (_k * (input - lastEma)) + lastEma;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override double Calculation()
|
protected override double Calculation()
|
||||||
@@ -96,7 +96,7 @@ public class Dema : AbstractBase
|
|||||||
_lastEma2 = ema2;
|
_lastEma2 = ema2;
|
||||||
|
|
||||||
// Calculate final DEMA
|
// Calculate final DEMA
|
||||||
double result = 2 * compensatedEma1 - (ema2 * invE);
|
double result = (2 * compensatedEma1) - (ema2 * invE);
|
||||||
|
|
||||||
IsHot = _index >= WarmupPeriod;
|
IsHot = _index >= WarmupPeriod;
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ public class Dsma : AbstractBase
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private double CalculateSuperSmootherFilter()
|
private double CalculateSuperSmootherFilter()
|
||||||
{
|
{
|
||||||
return _c1Half * (_zeros + _zeros1) + _c2 * _filt1 + _c3 * _filt2;
|
return (_c1Half * (_zeros + _zeros1)) + (_c2 * _filt1) + (_c3 * _filt2);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@@ -155,7 +155,7 @@ public class Dsma : AbstractBase
|
|||||||
double alpha = CalculateAdaptiveAlpha(scaledFilt);
|
double alpha = CalculateAdaptiveAlpha(scaledFilt);
|
||||||
|
|
||||||
// DSMA calculation
|
// DSMA calculation
|
||||||
double dsma = alpha * Input.Value + (1 - alpha) * _lastDsma;
|
double dsma = (alpha * Input.Value) + ((1 - alpha) * _lastDsma);
|
||||||
|
|
||||||
// Update state variables
|
// Update state variables
|
||||||
_zeros1 = _zeros;
|
_zeros1 = _zeros;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class Dwma : AbstractBase
|
|||||||
_innerWma = new Wma(period);
|
_innerWma = new Wma(period);
|
||||||
_outerWma = new Wma(period);
|
_outerWma = new Wma(period);
|
||||||
Name = "Dwma";
|
Name = "Dwma";
|
||||||
WarmupPeriod = 2 * period - 1;
|
WarmupPeriod = (2 * period) - 1;
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -112,7 +112,7 @@ public class Ema : AbstractBase
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private double CalculateEma(double input, double lastEma)
|
private double CalculateEma(double input, double lastEma)
|
||||||
{
|
{
|
||||||
return _k * (input - lastEma) + lastEma;
|
return (_k * (input - lastEma)) + lastEma;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ public class Epma : AbstractBase
|
|||||||
{
|
{
|
||||||
// Using arithmetic sequence sum formula: n(a1 + an)/2
|
// Using arithmetic sequence sum formula: n(a1 + an)/2
|
||||||
// where a1 = (2p-1) and an = (2p-1) - 3(n-1)
|
// where a1 = (2p-1) and an = (2p-1) - 3(n-1)
|
||||||
double firstTerm = 2 * period - 1;
|
double firstTerm = (2 * period) - 1;
|
||||||
double lastTerm = firstTerm - 3 * (period - 1);
|
double lastTerm = firstTerm - (3 * (period - 1));
|
||||||
return period * (firstTerm + lastTerm) * 0.5;
|
return period * (firstTerm + lastTerm) * 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,11 +109,11 @@ public class Epma : AbstractBase
|
|||||||
double[] kernel = new double[period];
|
double[] kernel = new double[period];
|
||||||
double weightSum = CalculateKernelSum(period);
|
double weightSum = CalculateKernelSum(period);
|
||||||
double invWeightSum = 1.0 / weightSum;
|
double invWeightSum = 1.0 / weightSum;
|
||||||
double baseWeight = 2 * period - 1;
|
double baseWeight = (2 * period) - 1;
|
||||||
|
|
||||||
for (int i = 0; i < period; i++)
|
for (int i = 0; i < period; i++)
|
||||||
{
|
{
|
||||||
kernel[i] = (baseWeight - 3 * i) * invWeightSum;
|
kernel[i] = (baseWeight - (3 * i)) * invWeightSum;
|
||||||
}
|
}
|
||||||
|
|
||||||
return kernel;
|
return kernel;
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ public class Frama : AbstractBase
|
|||||||
double dimension = (System.Math.Log(n2 + _epsilon) - System.Math.Log(n1 + _epsilon)) / _log2;
|
double dimension = (System.Math.Log(n2 + _epsilon) - System.Math.Log(n1 + _epsilon)) / _log2;
|
||||||
double alpha = CalculateAlpha(dimension);
|
double alpha = CalculateAlpha(dimension);
|
||||||
|
|
||||||
_lastFrama = alpha * (Input.Value - _lastFrama) + _lastFrama;
|
_lastFrama = (alpha * (Input.Value - _lastFrama)) + _lastFrama;
|
||||||
|
|
||||||
IsHot = _index >= WarmupPeriod;
|
IsHot = _index >= WarmupPeriod;
|
||||||
return _lastFrama;
|
return _lastFrama;
|
||||||
|
|||||||
+1
-1
@@ -117,7 +117,7 @@ public class Hma : AbstractBase
|
|||||||
double wmaFullResult = _wmaFull.Calc(Input).Value;
|
double wmaFullResult = _wmaFull.Calc(Input).Value;
|
||||||
|
|
||||||
// Calculate 2*WMA(n/2) - WMA(n)
|
// Calculate 2*WMA(n/2) - WMA(n)
|
||||||
double intermediateResult = 2.0 * wmaHalfResult - wmaFullResult;
|
double intermediateResult = (2.0 * wmaHalfResult) - wmaFullResult;
|
||||||
|
|
||||||
// Calculate final WMA
|
// Calculate final WMA
|
||||||
var finalInput = new TValue(Input.Time, intermediateResult, Input.IsNew);
|
var finalInput = new TValue(Input.Time, intermediateResult, Input.IsNew);
|
||||||
|
|||||||
@@ -82,13 +82,13 @@ public class Htit : AbstractBase
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static double CalculateSmoothedPrice(double p0, double p1, double p2, double p3)
|
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)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static double CalculateHilbertTransform(double b0, double b2, double b4, double b6, double adj)
|
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)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@@ -122,7 +122,7 @@ public class Htit : AbstractBase
|
|||||||
return pr;
|
return pr;
|
||||||
}
|
}
|
||||||
|
|
||||||
double adj = 0.075 * _lastPd + 0.54;
|
double adj = (0.075 * _lastPd) + 0.54;
|
||||||
|
|
||||||
// Smooth and detrender
|
// Smooth and detrender
|
||||||
double sp = CalculateSmoothedPrice(_priceBuffer[0], _priceBuffer[1], _priceBuffer[2], _priceBuffer[3]);
|
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);
|
double jQ = CalculateHilbertTransform(_q1Buffer[0], _q1Buffer[2], _q1Buffer[4], _q1Buffer[6], adj);
|
||||||
|
|
||||||
// Phasor addition for 3-bar averaging
|
// Phasor addition for 3-bar averaging
|
||||||
double i2 = ALPHA * (i1 - jQ) + BETA * _i2Buffer[0];
|
double i2 = (ALPHA * (i1 - jQ)) + (BETA * _i2Buffer[0]);
|
||||||
double q2 = ALPHA * (q1 + jI) + BETA * _q2Buffer[0];
|
double q2 = (ALPHA * (q1 + jI)) + (BETA * _q2Buffer[0]);
|
||||||
|
|
||||||
_i2Buffer.Add(i2, Input.IsNew);
|
_i2Buffer.Add(i2, Input.IsNew);
|
||||||
_q2Buffer.Add(q2, Input.IsNew);
|
_q2Buffer.Add(q2, Input.IsNew);
|
||||||
|
|
||||||
// Homodyne discriminator
|
// Homodyne discriminator
|
||||||
double re = ALPHA * (i2 * _i2Buffer[1] + q2 * _q2Buffer[1]) + BETA * _reBuffer[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];
|
double im = (ALPHA * ((i2 * _q2Buffer[1]) - (q2 * _i2Buffer[1]))) + (BETA * _imBuffer[0]);
|
||||||
|
|
||||||
_reBuffer.Add(re, Input.IsNew);
|
_reBuffer.Add(re, Input.IsNew);
|
||||||
_imBuffer.Add(im, Input.IsNew);
|
_imBuffer.Add(im, Input.IsNew);
|
||||||
@@ -159,10 +159,10 @@ public class Htit : AbstractBase
|
|||||||
// Calculate period
|
// Calculate period
|
||||||
double pd = (im != 0 && re != 0) ? TWO_PI / System.Math.Atan(im / re) : 0;
|
double pd = (im != 0 && re != 0) ? TWO_PI / System.Math.Atan(im / re) : 0;
|
||||||
pd = ClampPeriod(pd, _lastPd);
|
pd = ClampPeriod(pd, _lastPd);
|
||||||
pd = ALPHA * pd + BETA * _lastPd;
|
pd = (ALPHA * pd) + (BETA * _lastPd);
|
||||||
_pdBuffer.Add(pd, Input.IsNew);
|
_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);
|
_sdBuffer.Add(sd, Input.IsNew);
|
||||||
|
|
||||||
// Smooth dominant cycle period
|
// Smooth dominant cycle period
|
||||||
|
|||||||
@@ -110,19 +110,19 @@ public class Hwma : AbstractBase
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private double CalculateLevel(double input)
|
private double CalculateLevel(double input)
|
||||||
{
|
{
|
||||||
return _oneMinusNa * (_pF + _pV + _halfA * _pA) + _nA * input;
|
return (_oneMinusNa * (_pF + _pV + (_halfA * _pA))) + (_nA * input);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private double CalculateVelocity(double F)
|
private double CalculateVelocity(double F)
|
||||||
{
|
{
|
||||||
return _oneMinusNb * (_pV + _pA) + _nB * (F - _pF);
|
return (_oneMinusNb * (_pV + _pA)) + (_nB * (F - _pF));
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private double CalculateAcceleration(double V)
|
private double CalculateAcceleration(double V)
|
||||||
{
|
{
|
||||||
return _oneMinusNc * _pA + _nC * (V - _pV);
|
return (_oneMinusNc * _pA) + (_nC * (V - _pV));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override double Calculation()
|
protected override double Calculation()
|
||||||
@@ -152,6 +152,6 @@ public class Hwma : AbstractBase
|
|||||||
_pA = A;
|
_pA = A;
|
||||||
|
|
||||||
IsHot = _index >= WarmupPeriod;
|
IsHot = _index >= WarmupPeriod;
|
||||||
return F + V + _halfA * A;
|
return F + V + (_halfA * A);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -61,7 +61,7 @@ public class Jma : AbstractBase
|
|||||||
|
|
||||||
_vsumBuff = new CircularBuffer(buffer);
|
_vsumBuff = new CircularBuffer(buffer);
|
||||||
_avoltyBuff = new CircularBuffer(65);
|
_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);
|
_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);
|
_pow1 = System.Math.Max(_len1 - 2.0, 0.5);
|
||||||
@@ -160,12 +160,12 @@ public class Jma : AbstractBase
|
|||||||
_lowerBand = (del2 <= 0) ? price : price - (Kv * del2);
|
_lowerBand = (del2 <= 0) ? price : price - (Kv * del2);
|
||||||
|
|
||||||
double alpha = System.Math.Pow(_beta, pow2);
|
double alpha = System.Math.Pow(_beta, pow2);
|
||||||
double ma1 = price + alpha * (_prevMa1 - price);
|
double ma1 = price + (alpha * (_prevMa1 - price));
|
||||||
_prevMa1 = ma1;
|
_prevMa1 = ma1;
|
||||||
|
|
||||||
double det0 = price + _beta * (_prevDet0 - price + ma1) - ma1;
|
double det0 = price + (_beta * (_prevDet0 - price + ma1)) - ma1;
|
||||||
_prevDet0 = det0;
|
_prevDet0 = det0;
|
||||||
double ma2 = ma1 + _phase * det0;
|
double ma2 = ma1 + (_phase * det0);
|
||||||
|
|
||||||
double det1 = ((ma2 - _prevJma) * _oneMinusAlphaSquared) + (_alphaSquared * _prevDet1);
|
double det1 = ((ma2 - _prevJma) * _oneMinusAlphaSquared) + (_alphaSquared * _prevDet1);
|
||||||
_prevDet1 = det1;
|
_prevDet1 = det1;
|
||||||
|
|||||||
@@ -90,13 +90,13 @@ public class Ltma : AbstractBase
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private double CalculateLaguerreStage(double input, double prev, double prevPrev)
|
private double CalculateLaguerreStage(double input, double prev, double prevPrev)
|
||||||
{
|
{
|
||||||
return -_gamma * input + prev + _gamma * prevPrev;
|
return (-_gamma * input) + prev + (_gamma * prevPrev);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private double CombineOutputs(double l0, double l1, double l2, double l3)
|
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()
|
protected override double Calculation()
|
||||||
@@ -104,7 +104,7 @@ public class Ltma : AbstractBase
|
|||||||
ManageState(Input.IsNew);
|
ManageState(Input.IsNew);
|
||||||
|
|
||||||
// First stage
|
// First stage
|
||||||
double l0 = _oneMinusGamma * Input.Value + _gamma * _prevL0;
|
double l0 = (_oneMinusGamma * Input.Value) + (_gamma * _prevL0);
|
||||||
|
|
||||||
// Subsequent stages using helper method
|
// Subsequent stages using helper method
|
||||||
double l1 = CalculateLaguerreStage(l0, _prevL0, _prevL1);
|
double l1 = CalculateLaguerreStage(l0, _prevL0, _prevL1);
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public class Maaf : AbstractBase
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private double CalculateSmooth()
|
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)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@@ -141,7 +141,7 @@ public class Maaf : AbstractBase
|
|||||||
{
|
{
|
||||||
double alpha = CalculateAlpha(length);
|
double alpha = CalculateAlpha(length);
|
||||||
double value1 = GetMedian(length);
|
double value1 = GetMedian(length);
|
||||||
value2 = alpha * (smooth - _prevValue2) + _prevValue2;
|
value2 = (alpha * (smooth - _prevValue2)) + _prevValue2;
|
||||||
|
|
||||||
if (value1 != 0)
|
if (value1 != 0)
|
||||||
{
|
{
|
||||||
@@ -153,7 +153,7 @@ public class Maaf : AbstractBase
|
|||||||
|
|
||||||
length = System.Math.Max(length, 3);
|
length = System.Math.Max(length, 3);
|
||||||
double finalAlpha = CalculateAlpha(length);
|
double finalAlpha = CalculateAlpha(length);
|
||||||
double filter = finalAlpha * (smooth - _prevFilter) + _prevFilter;
|
double filter = (finalAlpha * (smooth - _prevFilter)) + _prevFilter;
|
||||||
|
|
||||||
_prevFilter = filter;
|
_prevFilter = filter;
|
||||||
_prevValue2 = value2;
|
_prevValue2 = value2;
|
||||||
|
|||||||
+12
-12
@@ -100,13 +100,13 @@ public class Mama : AbstractBase
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private double CalculateSmooth()
|
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)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static double CalculateHilbertTransform(CircularBuffer buffer, double adj)
|
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)]
|
[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, 0.67 * _pd[^2], 1.5 * _pd[^2]);
|
||||||
period = System.Math.Clamp(period, 6.0, 50.0);
|
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()
|
protected override double Calculation()
|
||||||
@@ -132,7 +132,7 @@ public class Mama : AbstractBase
|
|||||||
|
|
||||||
if (_index > 6)
|
if (_index > 6)
|
||||||
{
|
{
|
||||||
double adj = 0.075 * _pd[^1] + 0.54;
|
double adj = (0.075 * _pd[^1]) + 0.54;
|
||||||
|
|
||||||
// Smooth and Detrender
|
// Smooth and Detrender
|
||||||
_sm.Add(CalculateSmooth(), Input.IsNew);
|
_sm.Add(CalculateSmooth(), Input.IsNew);
|
||||||
@@ -151,16 +151,16 @@ public class Mama : AbstractBase
|
|||||||
double q2 = _q1[^1] + jI;
|
double q2 = _q1[^1] + jI;
|
||||||
_i2.Add(i2, Input.IsNew);
|
_i2.Add(i2, Input.IsNew);
|
||||||
_q2.Add(q2, Input.IsNew);
|
_q2.Add(q2, Input.IsNew);
|
||||||
_i2[^1] = _alpha02 * _i2[^1] + _alpha08 * _i2[^2];
|
_i2[^1] = (_alpha02 * _i2[^1]) + (_alpha08 * _i2[^2]);
|
||||||
_q2[^1] = _alpha02 * _q2[^1] + _alpha08 * _q2[^2];
|
_q2[^1] = (_alpha02 * _q2[^1]) + (_alpha08 * _q2[^2]);
|
||||||
|
|
||||||
// Homodyne discriminator
|
// Homodyne discriminator
|
||||||
double re = _i2[^1] * _i2[^2] + _q2[^1] * _q2[^2];
|
double re = (_i2[^1] * _i2[^2]) + (_q2[^1] * _q2[^2]);
|
||||||
double im = _i2[^1] * _q2[^2] - _q2[^1] * _i2[^2];
|
double im = (_i2[^1] * _q2[^2]) - (_q2[^1] * _i2[^2]);
|
||||||
_re.Add(re, Input.IsNew);
|
_re.Add(re, Input.IsNew);
|
||||||
_im.Add(im, Input.IsNew);
|
_im.Add(im, Input.IsNew);
|
||||||
_re[^1] = _alpha02 * _re[^1] + _alpha08 * _re[^2];
|
_re[^1] = (_alpha02 * _re[^1]) + (_alpha08 * _re[^2]);
|
||||||
_im[^1] = _alpha02 * _im[^1] + _alpha08 * _im[^2];
|
_im[^1] = (_alpha02 * _im[^1]) + (_alpha08 * _im[^2]);
|
||||||
|
|
||||||
// Calculate and adjust period
|
// Calculate and adjust period
|
||||||
double period = CalculatePeriod(_im[^1], _re[^1]);
|
double period = CalculatePeriod(_im[^1], _re[^1]);
|
||||||
@@ -176,8 +176,8 @@ public class Mama : AbstractBase
|
|||||||
double alpha = System.Math.Clamp(_fastLimit / delta, _slowLimit, _fastLimit);
|
double alpha = System.Math.Clamp(_fastLimit / delta, _slowLimit, _fastLimit);
|
||||||
|
|
||||||
// Final indicators
|
// Final indicators
|
||||||
_mama = alpha * (_pr[^1] - _prevMama) + _prevMama;
|
_mama = (alpha * (_pr[^1] - _prevMama)) + _prevMama;
|
||||||
_fama = _famaAlpha * alpha * (_mama - _prevFama) + _prevFama;
|
_fama = (_famaAlpha * alpha * (_mama - _prevFama)) + _prevFama;
|
||||||
|
|
||||||
_prevMama = _mama;
|
_prevMama = _mama;
|
||||||
_prevFama = _fama;
|
_prevFama = _fama;
|
||||||
|
|||||||
+1
-1
@@ -51,7 +51,7 @@ public class Mma : AbstractBase
|
|||||||
_weights = new double[period];
|
_weights = new double[period];
|
||||||
for (int i = 0; i < period; i++)
|
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";
|
Name = "Mma";
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ public class Qema : AbstractBase
|
|||||||
double ema4 = CalculateEma(_ema4, ema3);
|
double ema4 = CalculateEma(_ema4, ema3);
|
||||||
|
|
||||||
// Combine EMAs using optimized formula
|
// 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;
|
IsHot = _index >= WarmupPeriod;
|
||||||
return _lastQema;
|
return _lastQema;
|
||||||
|
|||||||
@@ -105,9 +105,9 @@ public class Rema : AbstractBase
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private double CalculateRema(double alpha, double input)
|
private double CalculateRema(double alpha, double input)
|
||||||
{
|
{
|
||||||
double standardTerm = _lastRema + alpha * (input - _lastRema);
|
double standardTerm = _lastRema + (alpha * (input - _lastRema));
|
||||||
double regularizationTerm = _lastRema + (_lastRema - _prevRema);
|
double regularizationTerm = _lastRema + (_lastRema - _prevRema);
|
||||||
return (standardTerm + _lambda * regularizationTerm) * _lambdaPlus1Recip;
|
return (standardTerm + (_lambda * regularizationTerm)) * _lambdaPlus1Recip;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override double Calculation()
|
protected override double Calculation()
|
||||||
|
|||||||
+1
-1
@@ -98,7 +98,7 @@ public class Rma : AbstractBase
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private double CalculateRma(double input)
|
private double CalculateRma(double input)
|
||||||
{
|
{
|
||||||
return _k * input + _oneMinusK * _lastRma;
|
return (_k * input) + (_oneMinusK * _lastRma);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public class Smma : AbstractBase
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private double CalculateSmma(double input)
|
private double CalculateSmma(double input)
|
||||||
{
|
{
|
||||||
return (_lastSmma * _periodMinusOne + input) * _periodRecip;
|
return ((_lastSmma * _periodMinusOne) + input) * _periodRecip;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override double Calculation()
|
protected override double Calculation()
|
||||||
|
|||||||
+4
-4
@@ -60,8 +60,8 @@ public class T3 : AbstractBase
|
|||||||
double v3 = v2 * vfactor;
|
double v3 = v2 * vfactor;
|
||||||
_c1 = -v3;
|
_c1 = -v3;
|
||||||
_c2 = 3.0 * (v2 + v3);
|
_c2 = 3.0 * (v2 + v3);
|
||||||
_c3 = -3.0 * (2.0 * v2 + vfactor + v3);
|
_c3 = -3.0 * ((2.0 * v2) + vfactor + v3);
|
||||||
_c4 = 1.0 + 3.0 * vfactor + v3 + 3.0 * v2;
|
_c4 = 1.0 + (3.0 * vfactor) + v3 + (3.0 * v2);
|
||||||
|
|
||||||
_buffer1 = new(period);
|
_buffer1 = new(period);
|
||||||
_buffer2 = new(period);
|
_buffer2 = new(period);
|
||||||
@@ -124,13 +124,13 @@ public class T3 : AbstractBase
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private double CalculateEma(double input, double lastEma)
|
private double CalculateEma(double input, double lastEma)
|
||||||
{
|
{
|
||||||
return _k * (input - lastEma) + lastEma;
|
return (_k * (input - lastEma)) + lastEma;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private double CalculateT3(double ema3, double ema4, double ema5, double ema6)
|
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()
|
protected override double Calculation()
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public class Tema : AbstractBase
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private double CalculateEma(double input, double lastEma, double invE)
|
private double CalculateEma(double input, double lastEma, double invE)
|
||||||
{
|
{
|
||||||
return _k * (input * invE - lastEma) + lastEma;
|
return (_k * ((input * invE) - lastEma)) + lastEma;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@@ -120,7 +120,7 @@ public class Tema : AbstractBase
|
|||||||
_lastEma3 = ema3;
|
_lastEma3 = ema3;
|
||||||
|
|
||||||
// Calculate final TEMA with compensation
|
// 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;
|
IsHot = _index >= WarmupPeriod;
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class Zlema : AbstractBase
|
|||||||
private double CalculateErrorCorrection()
|
private double CalculateErrorCorrection()
|
||||||
{
|
{
|
||||||
double lagValue = _buffer[System.Math.Max(0, _buffer.Count - 1 - _lag)];
|
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)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class GbmFeed : TBarSeries
|
|||||||
public TBar Generate(DateTime time, bool isNew = true)
|
public TBar Generate(DateTime time, bool isNew = true)
|
||||||
{
|
{
|
||||||
double dt = 1.0 / 252;
|
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 diffusion = _sigma * Math.Sqrt(dt) * GenerateNormalRandom();
|
||||||
|
|
||||||
double open = _lastClose;
|
double open = _lastClose;
|
||||||
@@ -40,8 +40,8 @@ public class GbmFeed : TBarSeries
|
|||||||
|
|
||||||
// Generate intra-bar price movements
|
// Generate intra-bar price movements
|
||||||
double maxMove = Math.Abs(close - open) * 1.5; // Allow for some extra movement within the bar
|
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 high = Math.Max(open, close) + (maxMove * GenerateRandomDouble());
|
||||||
double low = Math.Min(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
|
// Ensure high is always greater than or equal to both open and close
|
||||||
high = Math.Max(high, Math.Max(open, 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
|
// Ensure low is always less than or equal to both open and close
|
||||||
low = Math.Min(low, Math.Min(open, close));
|
low = Math.Min(low, Math.Min(open, close));
|
||||||
|
|
||||||
double volume = 1000 + GenerateRandomDouble() * 1000;
|
double volume = 1000 + (GenerateRandomDouble() * 1000);
|
||||||
|
|
||||||
if (isNew)
|
if (isNew)
|
||||||
{
|
{
|
||||||
|
|||||||
+1
-1
@@ -46,7 +46,7 @@ public sealed class Dpo : AbstractBase
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public Dpo(int period = 20)
|
public Dpo(int period = 20)
|
||||||
{
|
{
|
||||||
_shift = period / 2 + 1;
|
_shift = (period / 2) + 1;
|
||||||
WarmupPeriod = period + _shift;
|
WarmupPeriod = period + _shift;
|
||||||
Name = $"DPO({period})";
|
Name = $"DPO({period})";
|
||||||
_prices = new CircularBuffer(WarmupPeriod);
|
_prices = new CircularBuffer(WarmupPeriod);
|
||||||
|
|||||||
@@ -86,11 +86,11 @@ public sealed class Cfo : AbstractBase
|
|||||||
var n = (double)count;
|
var n = (double)count;
|
||||||
|
|
||||||
// Calculate linear regression coefficients
|
// Calculate linear regression coefficients
|
||||||
var slope = (n * _sumXY - _sumX * _sumY) / (n * _sumX2 - _sumX * _sumX);
|
var slope = ((n * _sumXY) - (_sumX * _sumY)) / ((n * _sumX2) - (_sumX * _sumX));
|
||||||
var intercept = (_sumY - slope * _sumX) / n;
|
var intercept = (_sumY - (slope * _sumX)) / n;
|
||||||
|
|
||||||
// Calculate forecast for next period
|
// Calculate forecast for next period
|
||||||
return intercept + slope * count;
|
return intercept + (slope * count);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
|||||||
@@ -96,6 +96,6 @@ public sealed class Cog : AbstractBase
|
|||||||
return 0.0;
|
return 0.0;
|
||||||
|
|
||||||
// Calculate center of gravity and normalize
|
// Calculate center of gravity and normalize
|
||||||
return -((numerator / denominator) - (_period + 1.0) / 2.0);
|
return -((numerator / denominator) - ((_period + 1.0) / 2.0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public sealed class Curvature : AbstractBase
|
|||||||
"Period must be greater than 2 for Curvature calculation.");
|
"Period must be greater than 2 for Curvature calculation.");
|
||||||
}
|
}
|
||||||
_period = period;
|
_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);
|
_slopeCalculator = new Slope(period);
|
||||||
_slopeBuffer = new CircularBuffer(period);
|
_slopeBuffer = new CircularBuffer(period);
|
||||||
Name = $"Curvature(period={period})";
|
Name = $"Curvature(period={period})";
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ public sealed class Kurtosis : AbstractBase
|
|||||||
if (variance2 < Epsilon)
|
if (variance2 < Epsilon)
|
||||||
return 0;
|
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)));
|
- (3 * (n - 1) * (n - 1) / ((n - 2) * (n - 3)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ public sealed class Percentile : AbstractBase
|
|||||||
double lowerValue = sortedValues[lowerIndex];
|
double lowerValue = sortedValues[lowerIndex];
|
||||||
double upperValue = sortedValues[upperIndex];
|
double upperValue = sortedValues[upperIndex];
|
||||||
double fraction = position - lowerIndex;
|
double fraction = position - lowerIndex;
|
||||||
return lowerValue + (upperValue - lowerValue) * fraction;
|
return lowerValue + ((upperValue - lowerValue) * fraction);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
|
|||||||
@@ -115,6 +115,6 @@ public sealed class Ap : AbstractBase
|
|||||||
|
|
||||||
// Project median line to current bar
|
// Project median line to current bar
|
||||||
double currentX = _index - p0.x;
|
double currentX = _index - p0.x;
|
||||||
return p0.y + slope * currentX;
|
return p0.y + (slope * currentX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public sealed class Jvolty : AbstractBase
|
|||||||
|
|
||||||
_vsumBuff = new CircularBuffer(VsumBufferSize);
|
_vsumBuff = new CircularBuffer(VsumBufferSize);
|
||||||
_avoltyBuff = new CircularBuffer(AvoltyBufferSize);
|
_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;
|
WarmupPeriod = period * 2;
|
||||||
Name = $"JVOLTY({period})";
|
Name = $"JVOLTY({period})";
|
||||||
@@ -155,9 +155,9 @@ public sealed class Jvolty : AbstractBase
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
private double CalculateJma(double price, double alpha, double ma1)
|
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;
|
_prevDet0 = det0;
|
||||||
double ma2 = ma1 + _phase * det0;
|
double ma2 = ma1 + (_phase * det0);
|
||||||
|
|
||||||
double det1 = ((ma2 - _prevJma) * (1 - alpha) * (1 - alpha)) + (alpha * alpha * _prevDet1);
|
double det1 = ((ma2 - _prevJma) * (1 - alpha) * (1 - alpha)) + (alpha * alpha * _prevDet1);
|
||||||
_prevDet1 = det1;
|
_prevDet1 = det1;
|
||||||
@@ -200,7 +200,7 @@ public sealed class Jvolty : AbstractBase
|
|||||||
|
|
||||||
// Apply JMA smoothing
|
// Apply JMA smoothing
|
||||||
double alpha = Math.Pow(_beta, pow2);
|
double alpha = Math.Pow(_beta, pow2);
|
||||||
double ma1 = (1 - alpha) * price + alpha * _prevMa1;
|
double ma1 = ((1 - alpha) * price) + (alpha * _prevMa1);
|
||||||
_prevMa1 = ma1;
|
_prevMa1 = ma1;
|
||||||
|
|
||||||
double jma = CalculateJma(price, alpha, ma1);
|
double jma = CalculateJma(price, alpha, ma1);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class CurvatureIndicator : Indicator, IWatchlistIndicator
|
|||||||
protected LineSeries? CurvatureSeries;
|
protected LineSeries? CurvatureSeries;
|
||||||
protected LineSeries? LineSeries;
|
protected LineSeries? LineSeries;
|
||||||
protected string? SourceName;
|
protected string? SourceName;
|
||||||
public int MinHistoryDepths => Periods * 2 - 1;
|
public int MinHistoryDepths => (Periods * 2) - 1;
|
||||||
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
|
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
|
||||||
|
|
||||||
public CurvatureIndicator()
|
public CurvatureIndicator()
|
||||||
|
|||||||
Reference in New Issue
Block a user