Skip to content

Commit c92cbab

Browse files
committed
Code cleanup.
1 parent 3c52bf0 commit c92cbab

7 files changed

Lines changed: 159 additions & 302 deletions

Algo.Gpu/Indicators/GpuGatorOscillatorCalculator.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
namespace StockSharp.Algo.Gpu.Indicators;
22

3-
using System.Reflection;
4-
53
/// <summary>
64
/// Parameter set for GPU Gator Oscillator calculation.
75
/// </summary>
@@ -17,9 +15,6 @@ namespace StockSharp.Algo.Gpu.Indicators;
1715
[StructLayout(LayoutKind.Sequential)]
1816
public struct GpuGatorOscillatorParams(int jawLength, int jawShift, int teethLength, int teethShift, int lipsLength, int lipsShift) : IGpuIndicatorParams
1917
{
20-
private static readonly FieldInfo _line1Field = typeof(GatorHistogram).GetField("_line1", BindingFlags.Instance | BindingFlags.NonPublic);
21-
private static readonly FieldInfo _line2Field = typeof(GatorHistogram).GetField("_line2", BindingFlags.Instance | BindingFlags.NonPublic);
22-
2318
/// <summary>
2419
/// Jaw SMMA period length.
2520
/// </summary>
@@ -61,19 +56,19 @@ public readonly void FromIndicator(IIndicator indicator)
6156
var histogram1 = gator.Histogram1;
6257
var histogram2 = gator.Histogram2;
6358

64-
if (_line1Field?.GetValue(histogram1) is AlligatorLine jaw)
59+
if (histogram1.Line1 is AlligatorLine jaw)
6560
{
6661
self.JawLength = jaw.Length;
6762
self.JawShift = jaw.Shift;
6863
}
6964

70-
if (_line2Field?.GetValue(histogram1) is AlligatorLine lips)
65+
if (histogram1.Line2 is AlligatorLine lips)
7166
{
7267
self.LipsLength = lips.Length;
7368
self.LipsShift = lips.Shift;
7469
}
7570

76-
if (_line2Field?.GetValue(histogram2) is AlligatorLine teeth)
71+
if (histogram2.Line2 is AlligatorLine teeth)
7772
{
7873
self.TeethLength = teeth.Length;
7974
self.TeethShift = teeth.Shift;

Algo.Gpu/Indicators/GpuKnowSureThingCalculator.cs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
namespace StockSharp.Algo.Gpu.Indicators;
22

3-
using System.Reflection;
4-
53
/// <summary>
64
/// Parameter set for GPU Know Sure Thing (KST) calculation.
75
/// </summary>
@@ -95,14 +93,14 @@ public readonly void FromIndicator(IIndicator indicator)
9593

9694
if (indicator is KnowSureThing kst)
9795
{
98-
self.Roc1Length = GetLength(kst, "_roc1", self.Roc1Length, defaults.Roc1Length);
99-
self.Roc2Length = GetLength(kst, "_roc2", self.Roc2Length, defaults.Roc2Length);
100-
self.Roc3Length = GetLength(kst, "_roc3", self.Roc3Length, defaults.Roc3Length);
101-
self.Roc4Length = GetLength(kst, "_roc4", self.Roc4Length, defaults.Roc4Length);
102-
self.Sma1Length = GetLength(kst, "_sma1", self.Sma1Length, defaults.Sma1Length);
103-
self.Sma2Length = GetLength(kst, "_sma2", self.Sma2Length, defaults.Sma2Length);
104-
self.Sma3Length = GetLength(kst, "_sma3", self.Sma3Length, defaults.Sma3Length);
105-
self.Sma4Length = GetLength(kst, "_sma4", self.Sma4Length, defaults.Sma4Length);
96+
self.Roc1Length = kst.Roc1.Length;
97+
self.Roc2Length = kst.Roc2.Length;
98+
self.Roc3Length = kst.Roc3.Length;
99+
self.Roc4Length = kst.Roc4.Length;
100+
self.Sma1Length = kst.Sma1.Length;
101+
self.Sma2Length = kst.Sma2.Length;
102+
self.Sma3Length = kst.Sma3.Length;
103+
self.Sma4Length = kst.Sma4.Length;
106104
self.SignalLength = kst.Signal?.Length ?? defaults.SignalLength;
107105
}
108106

@@ -118,18 +116,7 @@ public readonly void FromIndicator(IIndicator indicator)
118116
}
119117

120118
private static int EnsurePositive(int value, int fallback)
121-
=> value > 0 ? value : fallback;
122-
123-
private static int GetLength(KnowSureThing indicator, string fieldName, int currentValue, int fallback)
124-
{
125-
var field = typeof(KnowSureThing).GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
126-
if (field?.GetValue(indicator) is LengthIndicator<decimal> lengthIndicator)
127-
{
128-
return EnsurePositive(lengthIndicator.Length, fallback);
129-
}
130-
131-
return EnsurePositive(currentValue, fallback);
132-
}
119+
=> value > 0 ? value : fallback;
133120
}
134121

135122
/// <summary>

Algo.Gpu/Indicators/GpuMcClellanOscillatorCalculator.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
namespace StockSharp.Algo.Gpu.Indicators;
22

3-
using System.Reflection;
4-
53
/// <summary>
64
/// Parameter set for GPU McClellan Oscillator calculation.
75
/// </summary>
@@ -36,20 +34,8 @@ public readonly void FromIndicator(IIndicator indicator)
3634

3735
if (indicator is McClellanOscillator mc)
3836
{
39-
const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
40-
var type = mc.GetType();
41-
42-
var fastField = type.GetField("_ema19", flags);
43-
if (fastField?.GetValue(mc) is ExponentialMovingAverage fastEma)
44-
Unsafe.AsRef(in this).FastLength = fastEma.Length;
45-
else
46-
Unsafe.AsRef(in this).FastLength = 19;
47-
48-
var slowField = type.GetField("_ema39", flags);
49-
if (slowField?.GetValue(mc) is ExponentialMovingAverage slowEma)
50-
Unsafe.AsRef(in this).SlowLength = slowEma.Length;
51-
else
52-
Unsafe.AsRef(in this).SlowLength = 39;
37+
Unsafe.AsRef(in this).FastLength = mc.Ema19.Length;
38+
Unsafe.AsRef(in this).SlowLength = mc.Ema39.Length;
5339
}
5440
}
5541
}

0 commit comments

Comments
 (0)