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

59 lines
1.9 KiB
C#

using System.Drawing;
using System.Runtime.CompilerServices;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
[SkipLocalsInit]
public sealed class StochfIndicator : Indicator, IWatchlistIndicator
{
[InputParameter("K Length", sortIndex: 1, 1, 500, 1, 0)]
public int KLength { get; set; } = 5;
[InputParameter("D Period", sortIndex: 2, 1, 50, 1, 0)]
public int DPeriod { get; set; } = 3;
[InputParameter("Show cold values", sortIndex: 21)]
public bool ShowColdValues { get; set; } = true;
private Stochf _stochf = null!;
private readonly LineSeries _kSeries;
private readonly LineSeries _dSeries;
public static int MinHistoryDepths => 0;
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
public override string ShortName => $"STOCHF {KLength},{DPeriod}";
public override string SourceCodeLink => "https://github.com/mihakralj/QuanTAlib/blob/main/lib/oscillators/stochf/Stochf.cs";
public StochfIndicator()
{
OnBackGround = true;
SeparateWindow = true;
Name = "STOCHF";
Description = "Stochastic Fast Oscillator with raw %K and SMA %D lines";
_kSeries = new LineSeries(name: "K", color: Color.Green, width: 2, style: LineStyle.Solid);
_dSeries = new LineSeries(name: "D", color: Color.Red, width: 2, style: LineStyle.Solid);
AddLineSeries(_kSeries);
AddLineSeries(_dSeries);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void OnInit()
{
_stochf = new Stochf(KLength, DPeriod);
base.OnInit();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void OnUpdate(UpdateArgs args)
{
_ = _stochf.Update(this.GetInputBar(args), args.IsNewBar());
_kSeries.SetValue(_stochf.K.Value, _stochf.IsHot, ShowColdValues);
_dSeries.SetValue(_stochf.D.Value, _stochf.IsHot, ShowColdValues);
}
}