mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-21 12:08:05 +00:00
style patterns
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user