mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-02 11:37:42 +00:00
dc1902f4d5
- Implemented NVI indicator in Nvi.Quantower.cs with configurable start value and cold value display option. - Created unit tests for NVI functionality in Nvi.Tests.cs, covering various scenarios including initialization, updates, and edge cases. - Added validation tests in Nvi.Validation.Tests.cs to ensure NVI matches expected behavior against known implementations. - Developed comprehensive documentation for NVI in Nvi.md, detailing its historical context, mathematical foundation, and interpretation guide. - Included error handling for invalid input values and ensured compatibility with volume data.
53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using System.Drawing;
|
|
using System.Runtime.CompilerServices;
|
|
using TradingPlatform.BusinessLayer;
|
|
|
|
namespace QuanTAlib;
|
|
|
|
[SkipLocalsInit]
|
|
public sealed class NviIndicator : Indicator, IWatchlistIndicator
|
|
{
|
|
[InputParameter("Start Value", sortIndex: 10, 1, 10000, 1, 0)]
|
|
public double StartValue { get; set; } = 100;
|
|
|
|
[InputParameter("Show cold values", sortIndex: 21)]
|
|
public bool ShowColdValues { get; set; } = true;
|
|
|
|
private Nvi _nvi = null!;
|
|
private readonly LineSeries _series;
|
|
|
|
#pragma warning disable S2325 // Instance property required by Quantower indicator interface
|
|
public int MinHistoryDepths => 2;
|
|
#pragma warning restore S2325
|
|
int IWatchlistIndicator.MinHistoryDepths => 2;
|
|
|
|
public override string ShortName => $"NVI({StartValue})";
|
|
public override string SourceCodeLink => "https://github.com/mihakralj/QuanTAlib/blob/main/lib/volume/nvi/Nvi.Quantower.cs";
|
|
|
|
public NviIndicator()
|
|
{
|
|
OnBackGround = true;
|
|
SeparateWindow = true;
|
|
Name = "NVI - Negative Volume Index";
|
|
Description = "Negative Volume Index tracks price changes on days when volume decreases, reflecting smart money activity";
|
|
|
|
_series = new LineSeries(name: "NVI", color: Color.DarkCyan, width: 2, style: LineStyle.Solid);
|
|
AddLineSeries(_series);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
protected override void OnInit()
|
|
{
|
|
_nvi = new Nvi(StartValue);
|
|
base.OnInit();
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
protected override void OnUpdate(UpdateArgs args)
|
|
{
|
|
TBar bar = this.GetInputBar(args);
|
|
TValue result = _nvi.Update(bar, args.IsNewBar());
|
|
|
|
_series.SetValue(result.Value, _nvi.IsHot, ShowColdValues);
|
|
}
|
|
} |