Files
Miha Kralj 15f4bb90f3 feat: add 8 new indicators with full integration
New indicators:
- HWC (Holt-Winters Channel) — channels, 27 tests
- VWMACD (Volume-Weighted MACD) — momentum, 38 tests
- Squeeze Pro — oscillators, 69 tests
- BW_MFI (Bill Williams MFI) — oscillators
- DSTOCH (Double Stochastic) — oscillators
- ATRSTOP (ATR Trailing Stop) — reversals
- VSTOP (Volatility Stop) — reversals
- Convexity (Beta Convexity) — statistics, 23 tests

Integration:
- Python bridge: Exports.cs, _bridge.py, wrapper modules
- Documentation: _sidebar.md, _index.md pages, SPEC.md
- All analyzer warnings fixed (MA0074, xUnit2013, S2699)

Build: 0 warnings, 0 errors | Tests: 15,933 passed, 0 failed
2026-03-17 08:35:29 -07:00

75 lines
2.7 KiB
C#

using System.Drawing;
using System.Runtime.CompilerServices;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
[SkipLocalsInit]
public sealed class HwcIndicator : Indicator, IWatchlistIndicator
{
[InputParameter("Period", sortIndex: 1, 1, 2000, 1, 0)]
public int Period { get; set; } = 20;
[InputParameter("Multiplier", sortIndex: 2, 0.1, 10.0, 0.1, 1)]
public double Multiplier { get; set; } = 1.0;
[IndicatorExtensions.DataSourceInput(sortIndex: 3)]
public SourceType Source { get; set; } = SourceType.Close;
[InputParameter("Show cold values", sortIndex: 21)]
public bool ShowColdValues { get; set; } = true;
private Hwc _hwc = null!;
private readonly LineSeries _upperSeries;
private readonly LineSeries _middleSeries;
private readonly LineSeries _lowerSeries;
private string _sourceName = null!;
private Func<IHistoryItem, double> _priceSelector = null!;
public static int MinHistoryDepths => 0;
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
public override string ShortName => $"HWC({Period},{Multiplier:F1}):{_sourceName}";
public override string SourceCodeLink => "https://github.com/mihakralj/QuanTAlib/blob/main/lib/channels/hwc/Hwc.Quantower.cs";
public HwcIndicator()
{
OnBackGround = true;
SeparateWindow = false;
_sourceName = Source.ToString();
Name = "HWC - Holt-Winter Channel";
Description = "Adaptive volatility channel based on Holt-Winters triple exponential smoothing";
_upperSeries = new LineSeries(name: "Upper", color: Color.Red, width: 1, style: LineStyle.Solid);
_middleSeries = new LineSeries(name: "Middle", color: Color.Blue, width: 2, style: LineStyle.Solid);
_lowerSeries = new LineSeries(name: "Lower", color: Color.Green, width: 1, style: LineStyle.Solid);
AddLineSeries(_upperSeries);
AddLineSeries(_middleSeries);
AddLineSeries(_lowerSeries);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void OnInit()
{
_hwc = new Hwc(Period, Multiplier);
_sourceName = Source.ToString();
_priceSelector = Source.GetPriceSelector();
base.OnInit();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void OnUpdate(UpdateArgs args)
{
var item = HistoricalData[0, SeekOriginHistory.End];
double price = _priceSelector(item);
TValue input = new(item.TimeLeft, price);
_hwc.Update(input, args.IsNewBar());
_upperSeries.SetValue(_hwc.Upper.Value, _hwc.IsHot, ShowColdValues);
_middleSeries.SetValue(_hwc.Middle.Value, _hwc.IsHot, ShowColdValues);
_lowerSeries.SetValue(_hwc.Lower.Value, _hwc.IsHot, ShowColdValues);
}
}