mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-07-30 18:47:42 +00:00
76d2b50cbb
- Implemented the PvtIndicator class for calculating Price Volume Trend in Quantower. - Created unit tests for the Pvt class to validate calculations and state management. - Added validation tests to ensure consistency with OoplesFinance's implementation. - Developed a comprehensive documentation (Pvt.md) explaining the PVT concept, calculations, and usage. - Included methods for batch calculations and streaming updates for PVT.
59 lines
2.2 KiB
C#
59 lines
2.2 KiB
C#
using System.Drawing;
|
|
using System.Runtime.CompilerServices;
|
|
using TradingPlatform.BusinessLayer;
|
|
|
|
namespace QuanTAlib;
|
|
|
|
[SkipLocalsInit]
|
|
public sealed class PvdIndicator : Indicator, IWatchlistIndicator
|
|
{
|
|
[InputParameter("Price Period", sortIndex: 0, minimum: 1, maximum: 100, increment: 1, decimalPlaces: 0)]
|
|
public int PricePeriod { get; set; } = 14;
|
|
|
|
[InputParameter("Volume Period", sortIndex: 1, minimum: 1, maximum: 100, increment: 1, decimalPlaces: 0)]
|
|
public int VolumePeriod { get; set; } = 14;
|
|
|
|
[InputParameter("Smoothing Period", sortIndex: 2, minimum: 1, maximum: 50, increment: 1, decimalPlaces: 0)]
|
|
public int SmoothingPeriod { get; set; } = 3;
|
|
|
|
[InputParameter("Show cold values", sortIndex: 21)]
|
|
public bool ShowColdValues { get; set; } = true;
|
|
|
|
private Pvd _pvd = null!;
|
|
private readonly LineSeries _series;
|
|
|
|
#pragma warning disable S2325 // Instance property required by Quantower indicator interface
|
|
public int MinHistoryDepths => Math.Max(PricePeriod, VolumePeriod) + SmoothingPeriod + 1;
|
|
#pragma warning restore S2325
|
|
int IWatchlistIndicator.MinHistoryDepths => Math.Max(PricePeriod, VolumePeriod) + SmoothingPeriod + 1;
|
|
|
|
public override string ShortName => "PVD";
|
|
public override string SourceCodeLink => "https://github.com/mihakralj/QuanTAlib/blob/main/lib/volume/pvd/Pvd.Quantower.cs";
|
|
|
|
public PvdIndicator()
|
|
{
|
|
OnBackGround = true;
|
|
SeparateWindow = true;
|
|
Name = "PVD - Price Volume Divergence";
|
|
Description = "Price Volume Divergence measures divergence between price and volume momentum";
|
|
|
|
_series = new LineSeries(name: "PVD", color: Color.Yellow, width: 2, style: LineStyle.Solid);
|
|
AddLineSeries(_series);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
protected override void OnInit()
|
|
{
|
|
_pvd = new Pvd(PricePeriod, VolumePeriod, SmoothingPeriod);
|
|
base.OnInit();
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
protected override void OnUpdate(UpdateArgs args)
|
|
{
|
|
TBar bar = this.GetInputBar(args);
|
|
TValue result = _pvd.Update(bar, args.IsNewBar());
|
|
|
|
_series.SetValue(result.Value, _pvd.IsHot, ShowColdValues);
|
|
}
|
|
} |