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 Sp15Indicator : Indicator, IWatchlistIndicator
|
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 Sp15 _sp15 = 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 => $"SP15:{_sourceName}";
|
|
|
|
|
public override string SourceCodeLink => "https://github.com/mihakralj/QuanTAlib/blob/main/lib/trends_FIR/sp15/Sp15.Quantower.cs";
|
2026-01-18 19:02:03 -08:00
|
|
|
|
2026-02-21 20:45:38 -08:00
|
|
|
public Sp15Indicator()
|
2026-01-18 19:02:03 -08:00
|
|
|
{
|
|
|
|
|
OnBackGround = true;
|
2026-02-21 20:45:38 -08:00
|
|
|
SeparateWindow = false;
|
|
|
|
|
Name = "SP15 - Spencer 15-Point Moving Average";
|
|
|
|
|
Description = "Spencer 15-Point Moving Average";
|
|
|
|
|
_series = new LineSeries(name: "SP15", 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();
|
|
|
|
|
_sp15 = new Sp15();
|
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 = _sp15.Update(new TValue(item.TimeLeft.Ticks, _priceSelector(item)), isNew).Value;
|
|
|
|
|
_series.SetValue(value, _sp15.IsHot, ShowColdValues);
|
2026-01-18 19:02:03 -08:00
|
|
|
}
|
|
|
|
|
}
|