mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-15 17:18:05 +00:00
- Introduced YZV class for calculating Yang-Zhang Volatility, a comprehensive volatility measure that incorporates overnight, open-to-close, and high-low components. - Implemented calculation methods, including batch processing for TBarSeries and spans. - Added documentation for YZV, detailing its mathematical foundation, performance profile, and trading applications. - Updated volume index documentation to reflect changes in file paths. - Refactored VWMA calculation method to use a more generic source parameter instead of price.
55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
using System.Drawing;
|
|
using System.Runtime.CompilerServices;
|
|
using TradingPlatform.BusinessLayer;
|
|
|
|
namespace QuanTAlib;
|
|
|
|
[SkipLocalsInit]
|
|
public sealed class BiasIndicator : Indicator, IWatchlistIndicator
|
|
{
|
|
[InputParameter("Period", sortIndex: 0, minimum: 1, maximum: 10000)]
|
|
public int Period { get; set; } = 20;
|
|
|
|
[IndicatorExtensions.DataSourceInput]
|
|
public SourceType Source { get; set; } = SourceType.Close;
|
|
|
|
[InputParameter("Show cold values", sortIndex: 21)]
|
|
public bool ShowColdValues { get; set; } = true;
|
|
|
|
private Bias _bias = null!;
|
|
private readonly LineSeries _series;
|
|
private string _sourceName = null!;
|
|
private Func<IHistoryItem, double> _priceSelector = null!;
|
|
|
|
public static int MinHistoryDepths => 0;
|
|
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
|
|
|
|
public override string ShortName => $"BIAS({Period}):{_sourceName}";
|
|
|
|
public BiasIndicator()
|
|
{
|
|
OnBackGround = true;
|
|
SeparateWindow = true;
|
|
Name = "BIAS - Price Deviation from SMA";
|
|
Description = "Measures the percentage difference between price and its Simple Moving Average";
|
|
_series = new LineSeries(name: "BIAS", color: IndicatorExtensions.Statistics, width: 2, style: LineStyle.Solid);
|
|
AddLineSeries(_series);
|
|
}
|
|
|
|
protected override void OnInit()
|
|
{
|
|
_priceSelector = Source.GetPriceSelector();
|
|
_sourceName = Source.ToString();
|
|
_bias = new Bias(Period);
|
|
base.OnInit();
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
protected override void OnUpdate(UpdateArgs args)
|
|
{
|
|
bool isNew = args.IsNewBar();
|
|
var item = HistoricalData[Count - 1, SeekOriginHistory.Begin];
|
|
double value = _bias.Update(new TValue(item.TimeLeft.Ticks, _priceSelector(item)), isNew).Value;
|
|
_series.SetValue(value, _bias.IsHot, ShowColdValues);
|
|
}
|
|
} |