Files

42 lines
1.1 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 RviIndicator : Indicator, IWatchlistIndicator
2024-10-04 21:31:25 -07:00
{
2024-10-12 20:36:37 -07:00
[InputParameter("Periods", sortIndex: 1, 2, 100, 1, 0)]
public int Periods { get; set; } = 10;
2024-10-04 21:31:25 -07:00
private Rvi? rvi;
2024-10-12 20:36:37 -07:00
protected LineSeries? RviSeries;
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 RviIndicator()
2024-10-04 21:31:25 -07:00
{
Name = "RVI - Relative Volatility Index";
2024-10-11 18:02:09 -07:00
Description = "Measures the direction of volatility, helping to identify overbought or oversold conditions in price.";
2024-10-04 21:31:25 -07:00
SeparateWindow = true;
2024-11-06 20:56:32 -08:00
RviSeries = new("RVI", color: IndicatorExtensions.Volatility, 2, LineStyle.Solid);
2024-10-12 20:36:37 -07:00
AddLineSeries(RviSeries);
}
protected override void OnInit()
{
rvi = new Rvi(Periods);
base.OnInit();
}
protected override void OnUpdate(UpdateArgs args)
2024-10-04 21:31:25 -07:00
{
2024-10-12 20:36:37 -07:00
TBar input = IndicatorExtensions.GetInputBar(this, args);
TValue result = rvi!.Calc(input);
RviSeries!.SetValue(result.Value);
2024-10-04 21:31:25 -07:00
}
2024-10-12 20:36:37 -07:00
public override string ShortName => $"RVI ({Periods})";
2024-10-04 21:31:25 -07:00
}