Files
QuanTAlib/lib/oscillators/dymi/Dymi.Quantower.cs
T

79 lines
2.5 KiB
C#
Raw Normal View History

2026-02-26 22:02:52 -08:00
using System.Drawing;
using System.Runtime.CompilerServices;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
[SkipLocalsInit]
2026-03-16 12:45:13 -07:00
public sealed class DymiIndicator : Indicator, IWatchlistIndicator
2026-02-26 22:02:52 -08:00
{
[InputParameter("Base RSI Period", sortIndex: 1, 2, 500, 1, 0)]
public int BasePeriod { get; set; } = 14;
[InputParameter("Short StdDev Period", sortIndex: 2, 2, 500, 1, 0)]
public int ShortPeriod { get; set; } = 5;
[InputParameter("Long StdDev Period", sortIndex: 3, 2, 500, 1, 0)]
public int LongPeriod { get; set; } = 10;
[InputParameter("Min Period", sortIndex: 4, 2, 500, 1, 0)]
public int MinPeriod { get; set; } = 3;
[InputParameter("Max Period", sortIndex: 5, 2, 500, 1, 0)]
public int MaxPeriod { get; set; } = 30;
[IndicatorExtensions.DataSourceInput(sortIndex: 6)]
public SourceType Source { get; set; } = SourceType.Close;
[InputParameter("Show cold values", sortIndex: 21)]
public bool ShowColdValues { get; set; } = true;
2026-03-16 12:45:13 -07:00
private Dymi _dymi = null!;
2026-02-26 22:02:52 -08:00
private readonly LineSeries _series;
public static int MinHistoryDepths => 0;
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
public override string ShortName =>
2026-03-16 12:45:13 -07:00
$"DYMI ({BasePeriod},{ShortPeriod},{LongPeriod},{MinPeriod},{MaxPeriod})";
2026-02-26 22:02:52 -08:00
public override string SourceCodeLink =>
2026-03-16 12:45:13 -07:00
"https://github.com/mihakralj/QuanTAlib/blob/main/lib/oscillators/dymi/Dymi.Quantower.cs";
2026-02-26 22:02:52 -08:00
2026-03-16 12:45:13 -07:00
public DymiIndicator()
2026-02-26 22:02:52 -08:00
{
OnBackGround = true;
SeparateWindow = true;
2026-03-16 12:45:13 -07:00
Name = "DYMI - Dynamic Momentum Index";
2026-02-26 22:02:52 -08:00
Description = "Volatility-adaptive RSI by Chande & Kroll: period shortens in volatile markets, lengthens in quiet ones.";
2026-03-16 12:45:13 -07:00
_series = new LineSeries("DYMI", Color.Yellow, 2, LineStyle.Solid);
2026-02-26 22:02:52 -08:00
AddLineSeries(_series);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void OnInit()
{
2026-03-16 12:45:13 -07:00
_dymi = new Dymi(BasePeriod, ShortPeriod, LongPeriod, MinPeriod, MaxPeriod);
2026-02-26 22:02:52 -08:00
base.OnInit();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void OnUpdate(UpdateArgs args)
{
var priceSelector = Source.GetPriceSelector();
var item = HistoricalData[0, SeekOriginHistory.End];
double price = priceSelector(item);
TValue input = new(item.TimeLeft, price);
2026-03-16 12:45:13 -07:00
TValue result = _dymi.Update(input, args.IsNewBar());
2026-02-26 22:02:52 -08:00
2026-03-16 12:45:13 -07:00
if (!_dymi.IsHot && !ShowColdValues)
2026-02-26 22:02:52 -08:00
{
return;
}
_series.SetValue(result.Value);
}
}