Files
QuanTAlib/lib/numerics/standardize/Standardize.Quantower.cs
T
Miha Kralj 915d7a007b Add Standardize class for Z-Score normalization and update project files
- Implemented the Standardize class for calculating Z-Score normalization over a specified lookback period.
- Updated NDepend badge SVG files to reflect new metrics.
- Modified NDepend project files to reference the updated solution file name.
- Removed outdated documentation files related to indicator proposals and channel documentation remediation.
- Updated workspace configuration to point to the new solution file.
2026-02-07 12:47:13 -08:00

63 lines
1.9 KiB
C#

using System.Drawing;
using TradingPlatform.BusinessLayer;
using static QuanTAlib.IndicatorExtensions;
namespace QuanTAlib;
/// <summary>
/// STANDARDIZE (Z-Score Normalization) Quantower indicator.
/// Calculates the z-score of values over a lookback period using sample standard deviation.
/// </summary>
public class StandardizeIndicator : Indicator, IWatchlistIndicator
{
[DataSourceInput]
public SourceType Source { get; set; } = SourceType.Close;
[InputParameter("Period", sortIndex: 0, minimum: 2, maximum: 1000, increment: 1)]
public int Period { get; set; } = 20;
[InputParameter("Show Cold Values", sortIndex: 100)]
public bool ShowColdValues { get; set; } = true;
private Standardize? _standardize;
private Func<IHistoryItem, double>? _selector;
public int MinHistoryDepths => Period;
public override string ShortName => $"STND({Period})";
public StandardizeIndicator()
{
Name = "STANDARDIZE - Z-Score Normalization";
Description = "Calculates the z-score of values over a lookback period using sample standard deviation";
SeparateWindow = true;
OnBackGround = true;
}
protected override void OnInit()
{
_standardize = new Standardize(Period);
_selector = Source.GetPriceSelector();
AddLineSeries(new LineSeries("Z-Score", Color.Yellow, 2, LineStyle.Solid));
}
protected override void OnUpdate(UpdateArgs args)
{
if (_standardize == null || _selector == null)
{
return;
}
var item = HistoricalData[0, SeekOriginHistory.End];
double value = _selector(item);
bool isNew = args.IsNewBar();
TValue input = new(item.TimeLeft, value);
_standardize.Update(input, isNew);
bool isHot = _standardize.IsHot;
LinesSeries[0].SetValue(_standardize.Last.Value, isHot, ShowColdValues);
}
}