Files

45 lines
1.3 KiB
C#
Raw Permalink Normal View History

2024-10-12 20:36:37 -07:00
using System.Drawing;
2024-10-04 21:31:25 -07:00
using TradingPlatform.BusinessLayer;
2024-10-12 20:36:37 -07:00
2024-10-04 21:31:25 -07:00
namespace QuanTAlib;
2024-10-12 20:36:37 -07:00
public class HistoricalIndicator : Indicator, IWatchlistIndicator
2024-10-04 21:31:25 -07:00
{
2024-10-12 20:36:37 -07:00
[InputParameter("Periods", sortIndex: 1, 1, 2000, 1, 0)]
public int Periods { get; set; } = 20;
2024-10-04 21:31:25 -07:00
[InputParameter("Annualized", sortIndex: 2)]
public bool IsAnnualized { get; set; } = true;
2024-10-26 23:54:55 -07:00
private Hv? historical;
2024-10-12 20:36:37 -07:00
protected LineSeries? HvSeries;
public int MinHistoryDepths => Periods;
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
2024-10-04 21:31:25 -07:00
2024-10-12 20:36:37 -07:00
public HistoricalIndicator()
2024-10-04 21:31:25 -07:00
{
Name = "HV - Historical Volatility";
2024-10-11 18:02:09 -07:00
Description = "Measures price fluctuations over time, indicating market volatility based on past price movements.";
2024-10-04 21:31:25 -07:00
SeparateWindow = true;
2024-10-12 20:36:37 -07:00
2024-11-06 20:56:32 -08:00
HvSeries = new("HV", color: IndicatorExtensions.Volatility, 2, LineStyle.Solid);
2024-10-12 20:36:37 -07:00
AddLineSeries(HvSeries);
2024-10-04 21:31:25 -07:00
}
2024-10-12 20:36:37 -07:00
protected override void OnInit()
2024-10-04 21:31:25 -07:00
{
2024-10-26 23:54:55 -07:00
historical = new(Periods, IsAnnualized);
2024-10-12 20:36:37 -07:00
base.OnInit();
2024-10-04 21:31:25 -07:00
}
2024-10-12 20:36:37 -07:00
protected override void OnUpdate(UpdateArgs args)
{
TBar input = IndicatorExtensions.GetInputBar(this, args);
TValue result = historical!.Calc(input);
HvSeries!.SetValue(result.Value);
}
public override string ShortName => $"HV ({Periods}{(IsAnnualized ? " - Annualized" : "")})";
2024-10-11 18:02:09 -07:00
}