style patterns

This commit is contained in:
Miha Kralj
2026-01-25 16:01:45 -08:00
parent 2836f253c4
commit e59665c8f0
399 changed files with 6892 additions and 1323 deletions
+11 -1
View File
@@ -41,7 +41,10 @@ public class SlopeIndicator : Indicator, IWatchlistIndicator
protected override void OnUpdate(UpdateArgs args)
{
if (_slope == null || _selector == null) return;
if (_slope == null || _selector == null)
{
return;
}
var item = HistoricalData[0, SeekOriginHistory.End];
double value = _selector(item);
@@ -60,11 +63,18 @@ public class SlopeIndicator : Indicator, IWatchlistIndicator
double slope = _slope.Last.Value;
Color color;
if (slope > 0)
{
color = Color.Green;
}
else if (slope < 0)
{
color = Color.Red;
}
else
{
color = Color.Gray;
}
LinesSeries[0].SetMarker(0, new IndicatorLineMarker(color));
}
}
+2 -2
View File
@@ -241,10 +241,10 @@ public class SlopeTests
{
var source = new TSeries();
var slope = new Slope(source);
source.Add(new TValue(DateTime.UtcNow, 10));
source.Add(new TValue(DateTime.UtcNow, 20));
Assert.True(slope.IsHot);
Assert.Equal(10, slope.Last.Value);
}
+14 -3
View File
@@ -98,7 +98,10 @@ public sealed class Slope : AbstractBase
public override TSeries Update(TSeries source)
{
if (source.Count == 0) return [];
if (source.Count == 0)
{
return [];
}
int len = source.Count;
ReadOnlySpan<double> sourceValues = source.Values;
@@ -155,14 +158,22 @@ public sealed class Slope : AbstractBase
public static void Calculate(ReadOnlySpan<double> source, Span<double> output)
{
if (source.Length != output.Length)
{
throw new ArgumentException("Source and output must have the same length", nameof(output));
}
int len = source.Length;
if (len == 0) return;
if (len == 0)
{
return;
}
// First element has no previous - set to 0
output[0] = 0.0;
if (len == 1) return;
if (len == 1)
{
return;
}
int i = 1;