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
+2 -2
View File
@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>preview</LangVersion>
<NoWarn>$(NoWarn);NU1903;NU5104</NoWarn>
<NoWarn>$(NoWarn);NU1903;NU5104;NETSDK1057</NoWarn>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Deterministic>true</Deterministic>
@@ -41,7 +41,7 @@
<InvariantGlobalization>true</InvariantGlobalization>
<MetadataUpdaterSupport>false</MetadataUpdaterSupport>
<UseSystemResourceKeys>true</UseSystemResourceKeys>
</PropertyGroup>
<PropertyGroup>
+1
View File
@@ -21,6 +21,7 @@ public class EventingTests
("Ema", new object[] { DefaultPeriod, true }, new object[] { new TSeries(), DefaultPeriod, true }),
("Epma", new object[] { DefaultPeriod }, new object[] { new TSeries(), DefaultPeriod }),
("Pwma", new object[] { DefaultPeriod }, new object[] { new TSeries(), DefaultPeriod }),
("Fisher", new object[] { DefaultPeriod }, new object[] { new TSeries(), DefaultPeriod }),
("Frama", new object[] { DefaultPeriod }, new object[] { new TSeries(), DefaultPeriod }),
("Fwma", new object[] { DefaultPeriod }, new object[] { new TSeries(), DefaultPeriod }),
("Gma", new object[] { DefaultPeriod }, new object[] { new TSeries(), DefaultPeriod }),
+8
View File
@@ -152,5 +152,13 @@ namespace QuanTAlib
[Fact] public void Dmx() => TestIndicator<momentum::QuanTAlib.DmxIndicator>("dmx");
[Fact] public void Dpo() => TestIndicator<momentum::QuanTAlib.DpoIndicator>("dpo");
[Fact] public void Macd() => TestIndicator<momentum::QuanTAlib.MacdIndicator>("macd");
[Fact] public void Mom() => TestIndicator<momentum::QuanTAlib.MomIndicator>("Series");
[Fact] public void Pmo() => TestIndicator<momentum::QuanTAlib.PmoIndicator>("Series");
[Fact] public void Po() => TestIndicator<momentum::QuanTAlib.PoIndicator>("Series");
[Fact] public void Ppo() => TestIndicator<momentum::QuanTAlib.PpoIndicator>("Series");
[Fact] public void Roc() => TestIndicator<momentum::QuanTAlib.RocIndicator>("Series");
[Fact] public void Trix() => TestIndicator<momentum::QuanTAlib.TrixIndicator>("Series");
[Fact] public void Vel() => TestIndicator<momentum::QuanTAlib.VelIndicator>("Series");
[Fact] public void Vortex() => TestIndicatorMultipleFields<momentum::QuanTAlib.VortexIndicator>(new[] { "PlusLine", "MinusLine" });
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
✔️ AFIRMA - Adaptive FIR Moving Average
✔️ ALMA - Arnaud Legoux Moving Average
✔️ CONVOLUTION - 1D Convolution with sliding kernel
✔️ DEMA - Double Exponential Moving Average
✔️ DSMA - Dynamic Simple Moving Average
✔️ DWMA - Dynamic Weighted Moving Average
@@ -17,7 +18,7 @@
✔️ KAMA - Kaufman Adaptive Moving Average
✔️ LTMA - Linear Time Moving Average
✔️ MAAF - Moving Average Adaptive Filter
✔️ *MAMA - MESA Adaptive Moving Average (MAMA, FAMA)
✔️ MAMA - MESA Adaptive Moving Average (MAMA, FAMA)
✔️ MGDI - McGinley Dynamic Indicator
✔️ MMA - Modified Moving Average
✔️ PWMA - Parabolic Weighted Moving Average
-1
View File
@@ -31,7 +31,6 @@ public sealed class Fisher : AbstractBase
private readonly int _period;
private readonly double[] _prices;
private double _prevFisher;
private double _prevValue;
/// <param name="source">The data source object that publishes updates.</param>
/// <param name="period">The calculation period (default: 10)</param>
-2
View File
@@ -76,7 +76,5 @@ public class AfirmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -70,6 +70,5 @@ public class AlmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -64,6 +64,5 @@ public class DemaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -68,6 +68,5 @@ public class DsmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -64,6 +64,5 @@ public class DwmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -66,6 +66,5 @@ public class EmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -64,6 +64,5 @@ public class EpmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -64,6 +64,5 @@ public class FramaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -64,6 +64,5 @@ public class FwmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -64,6 +64,5 @@ public class GmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -64,6 +64,5 @@ public class HmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -61,6 +61,5 @@ public class HtitIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
+1 -2
View File
@@ -55,7 +55,7 @@ public class HwmaIndicator : Indicator, IWatchlistIndicator
protected override void OnInit()
{
if (NA == 0 && NB == 0 && NC == 0)
if ((NA, NB, NC) == (0, 0, 0))
{
ma = new Hwma(Periods);
}
@@ -80,6 +80,5 @@ public class HwmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -70,6 +70,5 @@ public class JmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -70,6 +70,5 @@ public class KamaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -64,6 +64,5 @@ public class LtmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -67,6 +67,5 @@ public class MaafIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -73,6 +73,5 @@ public class MamaIndicator : Indicator, IWatchlistIndicator
base.OnPaintChart(args);
this.PaintSmoothCurve(args, MamaSeries!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.PaintSmoothCurve(args, FamaSeries!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -67,6 +67,5 @@ public class MgdiIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -64,6 +64,5 @@ public class MmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -64,6 +64,5 @@ public class PwmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -67,6 +67,5 @@ public class RemaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -64,6 +64,5 @@ public class RmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -64,6 +64,5 @@ public class SinemaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
+1 -2
View File
@@ -5,7 +5,7 @@ namespace QuanTAlib;
public class SmaIndicator : Indicator, IWatchlistIndicator
{
[InputParameter("Periods", sortIndex: 1, 1, 1000, 1, 0)]
[InputParameter("Period", sortIndex: 1, 1, 1000, 1, 0)]
public int Period { get; set; } = 14;
[InputParameter("Data source", sortIndex: 2, variants: [
@@ -67,6 +67,5 @@ public class SmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, error!.Value.ToString());
}
}
-1
View File
@@ -64,6 +64,5 @@ public class SmmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -70,6 +70,5 @@ public class T3Indicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -64,6 +64,5 @@ public class TemaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -64,6 +64,5 @@ public class TrimaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -70,6 +70,5 @@ public class VidyaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -64,6 +64,5 @@ public class WmaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-1
View File
@@ -67,6 +67,5 @@ public class ZlemaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, err!.Value.ToString());
}
}
@@ -0,0 +1,97 @@
using System.Drawing;
using System.Linq;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
public class ConvolutionIndicator : Indicator, IWatchlistIndicator
{
[InputParameter("Kernel (comma/space/semicolon separated numbers)", sortIndex: 1)]
public string KernelString { get; set; } = "0.25, 0.5, 0.25, -0.5";
[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 Convolution? conv;
private Mape? error;
protected LineSeries? Series;
protected string? SourceName;
private double[]? kernel;
public int MinHistoryDepths => kernel?.Length ?? 3;
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
public ConvolutionIndicator()
{
OnBackGround = true;
SeparateWindow = false;
SourceName = Source.ToString();
Name = "CONV - Convolution Filter";
Description = "Convolution Filter with custom kernel";
kernel = ParseKernel(KernelString);
Series = new(name: $"CONV {string.Join(",", kernel.Select(x => x.ToString("F2")))}",
color: IndicatorExtensions.Averages,
width: 2,
style: LineStyle.Solid);
AddLineSeries(Series);
}
private static double[] ParseKernel(string kernelStr)
{
// Split on common delimiters: comma, semicolon, space, tab, pipe
var numbers = kernelStr.Split(new[] { ',', ';', ' ', '\t', '|' },
StringSplitOptions.RemoveEmptyEntries |
StringSplitOptions.TrimEntries);
var kernel = new double[numbers.Length];
for (int i = 0; i < numbers.Length; i++)
{
if (!double.TryParse(numbers[i], out kernel[i]))
{
// Default to simple 3-point moving average if parsing fails
return new double[] { 0.25, 0.5, 0.25, -0.5 };
}
}
return kernel;
}
protected override void OnInit()
{
kernel = ParseKernel(KernelString);
conv = new Convolution(kernel);
error = new(kernel.Length);
SourceName = Source.ToString();
base.OnInit();
}
protected override void OnUpdate(UpdateArgs args)
{
TValue input = this.GetInputValue(args, Source);
TValue result = conv!.Calc(input);
error!.Calc(input, result);
Series!.SetMarker(0, Color.Transparent);
Series!.SetValue(result.Value);
}
public override string ShortName => $"CONV {KernelString}:{SourceName}";
public override void OnPaintChart(PaintChartEventArgs args)
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, kernel!.Length, showColdValues: ShowColdValues, tension: 0.2);
}
}
@@ -73,6 +73,5 @@ public class QemaIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
-2
View File
@@ -59,7 +59,5 @@ public class TestIndicator : Indicator, IWatchlistIndicator
{
base.OnPaintChart(args);
this.PaintSmoothCurve(args, Series!, ma!.WarmupPeriod, ShowColdValues, tension: 0.2);
this.DrawText(args, Description);
}
}
+2
View File
@@ -22,6 +22,8 @@ public static class IndicatorExtensions
public static readonly Color Statistics = Color.FromArgb(128, 128, 255); // #8080FF - Blue
public static readonly Color Oscillators = Color.FromArgb(255, 128, 255); // #FF80FF - Magenta
public static readonly Color Momentum = Color.FromArgb(128, 255, 255); // #80FFFF - Cyan
public static readonly Color Experiments = Color.FromArgb(255, 165, 0); // #FFA500 - Orange
public static TValue GetInputValue(this Indicator indicator, UpdateArgs args, SourceType source)
{
var historicalData = indicator.HistoricalData;
+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);
}
}