Files
Miha Kralj 951842acca Add validation tests for various volume and momentum indicators
- Introduced Massi validation tests to ensure mathematical properties hold for the Mass Index indicator.
- Added Va validation tests for Volume Accumulation, checking for finite outputs and correct accumulation behavior.
- Implemented Vf validation tests for Volume Force, verifying outputs for rising and falling prices, and ensuring batch and streaming results match.
- Created Vo validation tests for Volume Oscillator, confirming behavior with constant, increasing, and decreasing volumes.
- Developed Vroc validation tests for Volume Rate of Change, validating outputs for constant volume and changes in volume.
- Updated project file to include new momentum indicators (MACD and RSI) in the compilation.
2026-02-12 19:43:09 -08:00

60 lines
2.1 KiB
C#

using System.Drawing;
using System.Runtime.CompilerServices;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
[SkipLocalsInit]
public sealed class WillrIndicator : Indicator, IWatchlistIndicator
{
[InputParameter("Period", sortIndex: 0, 1, 500, 1, 0)]
public int Period { get; set; } = 14;
[InputParameter("Show cold values", sortIndex: 21)]
public bool ShowColdValues { get; set; } = true;
private Willr _indicator = null!;
private readonly LineSeries _series;
private readonly LineSeries _overbought;
private readonly LineSeries _oversold;
public static int MinHistoryDepths => 0;
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
public override string ShortName => $"WILLR({Period})";
public override string SourceCodeLink => "https://github.com/mihakralj/QuanTAlib/blob/main/lib/oscillators/willr/Willr.cs";
public WillrIndicator()
{
OnBackGround = true;
SeparateWindow = true;
Name = "WILLR - Williams %R";
Description = "Williams %R oscillator. Measures close position relative to highest high over lookback period. Range: -100 to 0.";
_series = new LineSeries(name: "Williams %R", color: Color.Yellow, width: 2, style: LineStyle.Solid);
_overbought = new LineSeries(name: "Overbought", color: Color.Gray, width: 1, style: LineStyle.Dash);
_oversold = new LineSeries(name: "Oversold", color: Color.Gray, width: 1, style: LineStyle.Dash);
AddLineSeries(_series);
AddLineSeries(_overbought);
AddLineSeries(_oversold);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void OnInit()
{
_indicator = new Willr(Period);
base.OnInit();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void OnUpdate(UpdateArgs args)
{
_ = _indicator.Update(this.GetInputBar(args), args.IsNewBar());
_series.SetValue(_indicator.Last.Value, _indicator.IsHot, ShowColdValues);
_overbought.SetValue(-20.0, _indicator.IsHot, ShowColdValues);
_oversold.SetValue(-80.0, _indicator.IsHot, ShowColdValues);
}
}