2026-01-18 19:02:03 -08:00
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using TradingPlatform.BusinessLayer;
|
|
|
|
|
|
|
|
|
|
namespace QuanTAlib;
|
|
|
|
|
|
|
|
|
|
[SkipLocalsInit]
|
2026-02-21 20:45:38 -08:00
|
|
|
public sealed class KaiserIndicator : Indicator, IWatchlistIndicator
|
2026-01-18 19:02:03 -08:00
|
|
|
{
|
2026-02-21 20:45:38 -08:00
|
|
|
[InputParameter("Period", sortIndex: 1, 2, 2000, 1, 0)]
|
|
|
|
|
public int Period { get; set; } = 14;
|
|
|
|
|
|
|
|
|
|
[InputParameter("Beta", sortIndex: 2, minimum: 0.0, maximum: 20.0, increment: 0.1, decimalPlaces: 1)]
|
|
|
|
|
public double Beta { get; set; } = 3.0;
|
2026-01-18 19:02:03 -08:00
|
|
|
|
|
|
|
|
[IndicatorExtensions.DataSourceInput]
|
|
|
|
|
public SourceType Source { get; set; } = SourceType.Close;
|
|
|
|
|
|
|
|
|
|
[InputParameter("Show cold values", sortIndex: 21)]
|
|
|
|
|
public bool ShowColdValues { get; set; } = true;
|
|
|
|
|
|
2026-02-21 20:45:38 -08:00
|
|
|
private Kaiser _kaiser = null!;
|
2026-02-20 18:44:56 -08:00
|
|
|
private readonly LineSeries _series;
|
|
|
|
|
private string _sourceName = null!;
|
2026-01-18 19:02:03 -08:00
|
|
|
private Func<IHistoryItem, double> _priceSelector = null!;
|
|
|
|
|
|
|
|
|
|
public static int MinHistoryDepths => 0;
|
|
|
|
|
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
|
|
|
|
|
|
2026-02-21 20:45:38 -08:00
|
|
|
public override string ShortName => $"KAISER {Period},{Beta:F1}:{_sourceName}";
|
|
|
|
|
public override string SourceCodeLink => "https://github.com/mihakralj/QuanTAlib/blob/main/lib/trends_FIR/kaiser/Kaiser.Quantower.cs";
|
2026-01-18 19:02:03 -08:00
|
|
|
|
2026-02-21 20:45:38 -08:00
|
|
|
public KaiserIndicator()
|
2026-01-18 19:02:03 -08:00
|
|
|
{
|
|
|
|
|
OnBackGround = true;
|
2026-02-21 20:45:38 -08:00
|
|
|
SeparateWindow = false;
|
|
|
|
|
Name = "KAISER - Kaiser Window Moving Average";
|
|
|
|
|
Description = "Kaiser Window Moving Average";
|
|
|
|
|
_series = new LineSeries(name: $"KAISER {Period}", color: IndicatorExtensions.Averages, width: 2, style: LineStyle.Solid);
|
2026-01-18 19:02:03 -08:00
|
|
|
AddLineSeries(_series);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInit()
|
|
|
|
|
{
|
|
|
|
|
_priceSelector = Source.GetPriceSelector();
|
2026-02-21 20:45:38 -08:00
|
|
|
_sourceName = Source.ToString();
|
|
|
|
|
_kaiser = new Kaiser(Period, Beta);
|
2026-01-18 19:02:03 -08:00
|
|
|
base.OnInit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
protected override void OnUpdate(UpdateArgs args)
|
|
|
|
|
{
|
2026-02-21 20:45:38 -08:00
|
|
|
bool isNew = args.IsNewBar();
|
2026-01-18 19:02:03 -08:00
|
|
|
var item = HistoricalData[Count - 1, SeekOriginHistory.Begin];
|
2026-02-21 20:45:38 -08:00
|
|
|
double value = _kaiser.Update(new TValue(item.TimeLeft.Ticks, _priceSelector(item)), isNew).Value;
|
|
|
|
|
_series.SetValue(value, _kaiser.IsHot, ShowColdValues);
|
2026-01-18 19:02:03 -08:00
|
|
|
}
|
|
|
|
|
}
|