moar Chart indicators

This commit is contained in:
Miha Kralj
2024-11-07 21:40:02 -08:00
parent 2a72b2881b
commit 351214ed31
49 changed files with 697 additions and 42 deletions
+67
View File
@@ -0,0 +1,67 @@
using System.Drawing;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
public class MomIndicator : Indicator
{
[InputParameter("Period", sortIndex: 1, minimum: 1, maximum: 2000, increment: 1)]
public int Period { get; set; } = 10;
[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;
[InputParameter("Show cold values", sortIndex: 21)]
public bool ShowColdValues { get; set; } = true;
private Mom? mom;
protected LineSeries? Series;
protected string? SourceName;
public override string ShortName => $"MOM({Period})";
public MomIndicator()
{
OnBackGround = true;
SeparateWindow = true;
SourceName = Source.ToString();
Name = "MOM - Momentum";
Description = "A basic momentum indicator that measures the change in price over a specified period";
Series = new(name: $"MOM({Period})", color: IndicatorExtensions.Momentum, width: 2, style: LineStyle.Solid);
AddLineSeries(Series);
}
protected override void OnInit()
{
mom = new Mom(period: Period);
SourceName = Source.ToString();
base.OnInit();
}
protected override void OnUpdate(UpdateArgs args)
{
TValue input = this.GetInputValue(args, Source);
TValue result = mom!.Calc(input);
Series!.SetValue(result.Value);
Series!.SetMarker(0, Color.Transparent);
}
public override void OnPaintChart(PaintChartEventArgs args)
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, mom!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
}
}
+70
View File
@@ -0,0 +1,70 @@
using System.Drawing;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
public class PmoIndicator : Indicator
{
[InputParameter("First Period", sortIndex: 1, minimum: 1, maximum: 2000, increment: 1)]
public int Period1 { get; set; } = 35;
[InputParameter("Second Period", sortIndex: 2, minimum: 1, maximum: 2000, increment: 1)]
public int Period2 { get; set; } = 20;
[InputParameter("Data source", sortIndex: 3, 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;
[InputParameter("Show cold values", sortIndex: 21)]
public bool ShowColdValues { get; set; } = true;
private Pmo? pmo;
protected LineSeries? Series;
protected string? SourceName;
public override string ShortName => $"PMO({Period1},{Period2})";
public PmoIndicator()
{
OnBackGround = true;
SeparateWindow = true;
SourceName = Source.ToString();
Name = "PMO - Price Momentum Oscillator";
Description = "A momentum indicator that uses exponential moving averages of ROC to identify overbought and oversold conditions";
Series = new(name: $"PMO({Period1},{Period2})", color: IndicatorExtensions.Momentum, width: 2, style: LineStyle.Solid);
AddLineSeries(Series);
}
protected override void OnInit()
{
pmo = new Pmo(period1: Period1, period2: Period2);
SourceName = Source.ToString();
base.OnInit();
}
protected override void OnUpdate(UpdateArgs args)
{
TValue input = this.GetInputValue(args, Source);
TValue result = pmo!.Calc(input);
Series!.SetValue(result.Value);
Series!.SetMarker(0, Color.Transparent);
}
public override void OnPaintChart(PaintChartEventArgs args)
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, pmo!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
}
}
+75
View File
@@ -0,0 +1,75 @@
using System.Drawing;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
public class PoIndicator : Indicator
{
[InputParameter("Fast Period", sortIndex: 1, minimum: 1, maximum: 2000, increment: 1)]
public int FastPeriod { get; set; } = 10;
[InputParameter("Slow Period", sortIndex: 2, minimum: 1, maximum: 2000, increment: 1)]
public int SlowPeriod { get; set; } = 21;
[InputParameter("Data source", sortIndex: 3, 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;
[InputParameter("Show cold values", sortIndex: 21)]
public bool ShowColdValues { get; set; } = true;
private Po? po;
protected LineSeries? Series;
protected string? SourceName;
public override string ShortName => $"PO({FastPeriod},{SlowPeriod})";
public PoIndicator()
{
OnBackGround = true;
SeparateWindow = true;
SourceName = Source.ToString();
Name = "PO - Price Oscillator";
Description = "A momentum indicator that measures the difference between two moving averages to identify price momentum";
Series = new(name: $"PO({FastPeriod},{SlowPeriod})", color: IndicatorExtensions.Momentum, width: 2, style: LineStyle.Solid);
AddLineSeries(Series);
}
protected override void OnInit()
{
if (FastPeriod >= SlowPeriod)
{
FastPeriod = 10;
SlowPeriod = 21;
}
po = new Po(fastPeriod: FastPeriod, slowPeriod: SlowPeriod);
SourceName = Source.ToString();
base.OnInit();
}
protected override void OnUpdate(UpdateArgs args)
{
TValue input = this.GetInputValue(args, Source);
TValue result = po!.Calc(input);
Series!.SetValue(result.Value);
Series!.SetMarker(0, Color.Transparent);
}
public override void OnPaintChart(PaintChartEventArgs args)
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, po!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
}
}
+75
View File
@@ -0,0 +1,75 @@
using System.Drawing;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
public class PpoIndicator : Indicator
{
[InputParameter("Fast Period", sortIndex: 1, minimum: 1, maximum: 2000, increment: 1)]
public int FastPeriod { get; set; } = 12;
[InputParameter("Slow Period", sortIndex: 2, minimum: 1, maximum: 2000, increment: 1)]
public int SlowPeriod { get; set; } = 26;
[InputParameter("Data source", sortIndex: 3, 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;
[InputParameter("Show cold values", sortIndex: 21)]
public bool ShowColdValues { get; set; } = true;
private Ppo? ppo;
protected LineSeries? Series;
protected string? SourceName;
public override string ShortName => $"PPO({FastPeriod},{SlowPeriod})";
public PpoIndicator()
{
OnBackGround = true;
SeparateWindow = true;
SourceName = Source.ToString();
Name = "PPO - Percentage Price Oscillator";
Description = "A momentum indicator that shows the percentage difference between two moving averages";
Series = new(name: $"PPO({FastPeriod},{SlowPeriod})", color: IndicatorExtensions.Momentum, width: 2, style: LineStyle.Solid);
AddLineSeries(Series);
}
protected override void OnInit()
{
if (FastPeriod >= SlowPeriod)
{
FastPeriod = 12;
SlowPeriod = 26;
}
ppo = new Ppo(fastPeriod: FastPeriod, slowPeriod: SlowPeriod);
SourceName = Source.ToString();
base.OnInit();
}
protected override void OnUpdate(UpdateArgs args)
{
TValue input = this.GetInputValue(args, Source);
TValue result = ppo!.Calc(input);
Series!.SetValue(result.Value);
Series!.SetMarker(0, Color.Transparent);
}
public override void OnPaintChart(PaintChartEventArgs args)
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ppo!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
}
}
+76
View File
@@ -0,0 +1,76 @@
using System.Drawing;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
public class RocIndicator : Indicator, IWatchlistIndicator
{
[InputParameter("Period", sortIndex: 1, minimum: 1, maximum: 2000, increment: 1)]
public int Period { get; set; } = 12;
[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;
[InputParameter("Show cold values", sortIndex: 21)]
public bool ShowColdValues { get; set; } = true;
private Roc? roc;
protected LineSeries? Series;
protected LineSeries? ZeroLine;
protected string? SourceName;
public int MinHistoryDepths => Math.Max(5, Period * 2);
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
public override string ShortName => $"ROC({Period})";
public RocIndicator()
{
OnBackGround = true;
SeparateWindow = true;
SourceName = Source.ToString();
Name = "ROC - Rate of Change";
Description = "A momentum indicator that measures the percentage change in price over a specified period";
Series = new(name: $"ROC({Period})", color: IndicatorExtensions.Momentum, width: 2, style: LineStyle.Solid);
ZeroLine = new("Zero", Color.Gray, 1, LineStyle.Dot);
AddLineSeries(Series);
AddLineSeries(ZeroLine);
}
protected override void OnInit()
{
roc = new Roc(period: Period);
SourceName = Source.ToString();
base.OnInit();
}
protected override void OnUpdate(UpdateArgs args)
{
if (args.Reason != UpdateReason.NewTick)
return;
TValue input = this.GetInputValue(args, Source);
TValue result = roc!.Calc(input);
Series!.SetValue(result.Value);
ZeroLine!.SetValue(0);
Series!.SetMarker(0, Color.Transparent);
}
public override void OnPaintChart(PaintChartEventArgs args)
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, roc!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
}
}
+67
View File
@@ -0,0 +1,67 @@
using System.Drawing;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
public class TrixIndicator : Indicator
{
[InputParameter("Period", sortIndex: 1, minimum: 1, maximum: 2000, increment: 1)]
public int Period { get; set; } = 18;
[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;
[InputParameter("Show cold values", sortIndex: 21)]
public bool ShowColdValues { get; set; } = true;
private Trix? trix;
protected LineSeries? Series;
protected string? SourceName;
public override string ShortName => $"TRIX({Period})";
public TrixIndicator()
{
OnBackGround = true;
SeparateWindow = true;
SourceName = Source.ToString();
Name = "TRIX - Triple Exponential Average Rate of Change";
Description = "A momentum oscillator that shows the percentage rate of change of a triple exponentially smoothed moving average";
Series = new(name: $"TRIX({Period})", color: IndicatorExtensions.Momentum, width: 2, style: LineStyle.Solid);
AddLineSeries(Series);
}
protected override void OnInit()
{
trix = new Trix(period: Period);
SourceName = Source.ToString();
base.OnInit();
}
protected override void OnUpdate(UpdateArgs args)
{
TValue input = this.GetInputValue(args, Source);
TValue result = trix!.Calc(input);
Series!.SetValue(result.Value);
Series!.SetMarker(0, Color.Transparent);
}
public override void OnPaintChart(PaintChartEventArgs args)
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, trix!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
}
}
+82
View File
@@ -0,0 +1,82 @@
using System.Drawing;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
public class VelIndicator : Indicator, IWatchlistIndicator
{
[InputParameter("Period", sortIndex: 1, minimum: 1, maximum: 2000, increment: 1)]
public int Period { get; set; } = 10;
[InputParameter("Phase", sortIndex: 2, minimum: -100, maximum: 100, increment: 1)]
public int Phase { get; set; } = 100;
[InputParameter("Factor", sortIndex: 3, minimum: 0.1, maximum: 0.9, increment: 0.1, decimalPlaces: 2)]
public double Factor { get; set; } = 0.25;
[InputParameter("Data source", sortIndex: 4, 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;
[InputParameter("Show cold values", sortIndex: 21)]
public bool ShowColdValues { get; set; } = true;
private Vel? vel;
protected LineSeries? Series;
protected LineSeries? ZeroLine;
protected string? SourceName;
public int MinHistoryDepths => Math.Max(5, Period * 2);
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
public override string ShortName => $"VEL({Period})";
public VelIndicator()
{
OnBackGround = true;
SeparateWindow = true;
SourceName = Source.ToString();
Name = "VEL - Velocity";
Description = "An enhanced momentum indicator that applies JMA smoothing to momentum calculation";
Series = new(name: $"VEL({Period})", color: IndicatorExtensions.Momentum, width: 2, style: LineStyle.Solid);
ZeroLine = new("Zero", Color.Gray, 1, LineStyle.Dot);
AddLineSeries(Series);
AddLineSeries(ZeroLine);
}
protected override void OnInit()
{
vel = new Vel(period: Period, phase: Phase, factor: Factor);
SourceName = Source.ToString();
base.OnInit();
}
protected override void OnUpdate(UpdateArgs args)
{
if (args.Reason != UpdateReason.NewTick)
return;
TValue input = this.GetInputValue(args, Source);
TValue result = vel!.Calc(input);
Series!.SetValue(result.Value);
ZeroLine!.SetValue(0);
Series!.SetMarker(0, Color.Transparent);
}
public override void OnPaintChart(PaintChartEventArgs args)
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, vel!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
}
}
+71
View File
@@ -0,0 +1,71 @@
using System.Drawing;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
public class VortexIndicator : Indicator, IWatchlistIndicator
{
[InputParameter("Periods", sortIndex: 1, 1, 2000, 1, 0)]
public int Periods { get; set; } = 14;
[InputParameter("Show cold values", sortIndex: 21)]
public bool ShowColdValues { get; set; } = true;
private Vortex? vortex;
protected LineSeries? ValueSeries;
protected LineSeries? PlusLine;
protected LineSeries? MinusLine;
protected LineSeries? ZeroLine;
public int MinHistoryDepths => Math.Max(5, Periods * 2);
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
public VortexIndicator()
{
Name = "VORTEX - Vortex Indicator";
Description = "A technical indicator consisting of two oscillating lines that identify trend reversals";
SeparateWindow = true;
ValueSeries = new($"VORTEX({Periods})", color: IndicatorExtensions.Momentum, 2, LineStyle.Solid);
PlusLine = new($"VI+({Periods})", color: Color.Green, 2, LineStyle.Solid);
MinusLine = new($"VI-({Periods})", color: Color.Red, 2, LineStyle.Solid);
ZeroLine = new("Zero", Color.Gray, 1, LineStyle.Dot);
AddLineSeries(ValueSeries);
AddLineSeries(PlusLine);
AddLineSeries(MinusLine);
AddLineSeries(ZeroLine);
}
protected override void OnInit()
{
vortex = new Vortex(Periods);
base.OnInit();
}
protected override void OnUpdate(UpdateArgs args)
{
TBar input = IndicatorExtensions.GetInputBar(this, args);
var result = vortex!.Calc(input);
ValueSeries!.SetValue(result);
PlusLine!.SetValue(vortex.ViPlus);
MinusLine!.SetValue(vortex.ViMinus);
ZeroLine!.SetValue(0);
ValueSeries!.SetMarker(0, Color.Transparent);
PlusLine!.SetMarker(0, Color.Transparent);
MinusLine!.SetMarker(0, Color.Transparent);
}
#pragma warning disable CA1416 // Validate platform compatibility
public override string ShortName => $"VORTEX({Periods})";
public override void OnPaintChart(PaintChartEventArgs args)
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, ValueSeries!, vortex!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.PaintSmoothCurve(args, PlusLine!, vortex!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.PaintSmoothCurve(args, MinusLine!, vortex!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
}
}