refresh with new QT DLL

This commit is contained in:
Miha Kralj
2024-10-12 20:36:37 -07:00
parent cc45cebeb4
commit b3b3b24a25
65 changed files with 2593 additions and 1189 deletions
+67 -10
View File
@@ -1,25 +1,82 @@
using System.Drawing;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
public class SlopeIndicator : IndicatorBase
public class SlopeIndicator : Indicator, IWatchlistIndicator
{
[InputParameter("Period", sortIndex: 1, 2, 2000, 1, 0)]
public int Period { get; set; } = 20;
[InputParameter("Periods", sortIndex: 1, 2, 1000, 1, 0)]
public int Periods { get; set; } = 20;
[InputParameter("Data source", sortIndex: 2, variants: [
"Open", SourceType.Open,
"High", SourceType.High,
"Low", SourceType.Low,
"Close", SourceType.Close,
"HL/2 (Median)", SourceType.HL2,
"OC/2 (Midpoint)", SourceType.OC2,
"OHL/3 (Mean)", SourceType.OHL3,
"HLC/3 (Typical)", SourceType.HLC3,
"OHLC/4 (Average)", SourceType.OHLC4,
"HLCC/4 (Weighted)", SourceType.HLCC4
])]
public SourceType Source { get; set; } = SourceType.Close;
private Slope? slope;
protected override AbstractBase QuanTAlib => slope!;
public override string ShortName => $"SLOPE {Period} : {SourceName}";
protected LineSeries? SlopeSeries;
protected LineSeries? LineSeries;
protected string? SourceName;
public int MinHistoryDepths => Periods;
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
public SlopeIndicator()
{
Name = "SLOPE - Trend Slope";
Description = "Measures the rate of change in price over a specified period, indicating trend strength and direction.";
Name = "Slope";
Description = "Calculates the slope of a linear regression line for the specified period";
SeparateWindow = true;
SourceName = Source.ToString();
SlopeSeries = new("Slope", Color.Blue, 2, LineStyle.Solid);
LineSeries = new("Regression Line", Color.Red, 1, LineStyle.Solid);
AddLineSeries(SlopeSeries);
AddLineSeries(LineSeries);
}
protected override void InitIndicator()
protected override void OnInit()
{
slope = new(Period);
MinHistoryDepths = slope.WarmupPeriod;
slope = new Slope(Periods);
SourceName = Source.ToString();
base.OnInit();
}
protected override void OnUpdate(UpdateArgs args)
{
TValue input = this.GetInputValue(args, Source);
TValue result = slope!.Calc(input);
SlopeSeries!.SetValue(result.Value);
if (slope.Line.HasValue)
{
LineSeries!.SetValue(slope.Line.Value);
}
}
public override string ShortName
{
get
{
var result = $"Slope ({Periods}:{SourceName})";
if (slope != null)
{
result += $" Slope: {Math.Round(SlopeSeries!.GetValue(), 6)}";
if (slope.Line.HasValue)
result += $", Line: {Math.Round(slope.Line.Value, 6)}";
if (slope.Intercept.HasValue)
result += $", Intercept: {Math.Round(slope.Intercept.Value, 6)}";
if (slope.RSquared.HasValue)
result += $", R²: {Math.Round(slope.RSquared.Value, 6)}";
}
return result;
}
}
}