mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-09 14:30:56 +00:00
dfeb23bf3d
- Implemented SgmaIndicator class in C# with properties for Period, Degree, and Source. - Added unit tests for SgmaIndicator covering constructor defaults, initialization, and various update scenarios. - Created a new Quantower adapter for the SGMA indicator, including input parameters and line series setup. - Removed legacy SGMA implementation and tests to streamline the codebase. - Updated project files to include new indicator and tests in the build process. - Generated a missing indicators report and outlined a plan for oscillator documentation rewrite.
59 lines
2.1 KiB
C#
59 lines
2.1 KiB
C#
using System.Runtime.CompilerServices;
|
|
using TradingPlatform.BusinessLayer;
|
|
|
|
namespace QuanTAlib;
|
|
|
|
[SkipLocalsInit]
|
|
public sealed class SgmaIndicator : Indicator, IWatchlistIndicator
|
|
{
|
|
[InputParameter("Period", sortIndex: 1, 3, 2000, 1, 0)]
|
|
public int Period { get; set; } = 9;
|
|
|
|
[InputParameter("Degree", sortIndex: 2, 0, 4, 1, 0)]
|
|
public int Degree { get; set; } = 2;
|
|
|
|
[IndicatorExtensions.DataSourceInput]
|
|
public SourceType Source { get; set; } = SourceType.Close;
|
|
|
|
[InputParameter("Show cold values", sortIndex: 21)]
|
|
public bool ShowColdValues { get; set; } = true;
|
|
|
|
private Sgma _sgma = null!;
|
|
private readonly LineSeries _series;
|
|
private string _sourceName = null!;
|
|
private Func<IHistoryItem, double> _priceSelector = null!;
|
|
|
|
public static int MinHistoryDepths => 0;
|
|
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
|
|
|
|
public override string ShortName => $"SGMA {Period},{Degree}:{_sourceName}";
|
|
public override string SourceCodeLink => "https://github.com/mihakralj/QuanTAlib/blob/main/lib/trends_FIR/sgma/Sgma.cs";
|
|
|
|
public SgmaIndicator()
|
|
{
|
|
OnBackGround = true;
|
|
SeparateWindow = false;
|
|
Name = "SGMA - Savitzky-Golay Moving Average";
|
|
Description = "Polynomial-fitting FIR filter preserving peaks and inflection points";
|
|
_series = new LineSeries(name: $"SGMA {Period}", color: IndicatorExtensions.Averages, width: 2, style: LineStyle.Solid);
|
|
AddLineSeries(_series);
|
|
}
|
|
|
|
protected override void OnInit()
|
|
{
|
|
_priceSelector = Source.GetPriceSelector();
|
|
_sourceName = Source.ToString();
|
|
_sgma = new Sgma(Period, Degree);
|
|
base.OnInit();
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
protected override void OnUpdate(UpdateArgs args)
|
|
{
|
|
bool isNew = args.IsNewBar();
|
|
var item = HistoricalData[Count - 1, SeekOriginHistory.Begin];
|
|
double value = _sgma.Update(new TValue(item.TimeLeft.Ticks, _priceSelector(item)), isNew).Value;
|
|
_series.SetValue(value, _sgma.IsHot, ShowColdValues);
|
|
}
|
|
}
|