Files
QuanTAlib/lib/dynamics/ht_trendmode/HtTrendmode.Quantower.cs
T
Miha Kralj 58f0812584 Add Vortex Indicator implementation and documentation
- Implemented Vortex Indicator in Vortex.cs, including calculation logic and event handling.
- Added detailed documentation for Vortex Indicator in Vortex.md, covering historical context, algorithm, outputs, and trading interpretation.
- Updated oscillators index to include TTM Wave indicator.
- Added TTM Wave documentation with algorithm and trading interpretation.
- Updated reversals index to include TTM Scalper Alert indicator.
- Added TTM Scalper Alert documentation with algorithm and trading strategy.
- Updated NDepend badges to reflect increased code metrics (classes, methods, lines of code, public types, comments, and complexity).
2026-02-06 07:43:40 -08:00

76 lines
2.8 KiB
C#

using System.Drawing;
using System.Runtime.CompilerServices;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
[SkipLocalsInit]
public sealed class HtTrendmodeIndicator : Indicator, IWatchlistIndicator
{
[InputParameter("Data source", 10)]
public SourceType SourceInput { get; set; } = SourceType.Close;
[InputParameter("Show cold values", sortIndex: 21)]
public bool ShowColdValues { get; set; } = true;
private HtTrendmode _indicator = null!;
private readonly LineSeries _trendModeSeries;
public static int MinHistoryDepths => 0;
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
public override string ShortName => "HT_TRENDMODE";
public override string SourceCodeLink => "https://github.com/mihakralj/QuanTAlib/blob/main/lib/dynamics/ht_trendmode/HtTrendmode.Quantower.cs";
public HtTrendmodeIndicator()
{
OnBackGround = true;
SeparateWindow = true;
Name = "HT_TRENDMODE - Hilbert Transform Trend Mode";
Description = "Determines if market is trending (1) or cycling (0)";
_trendModeSeries = new LineSeries(name: "TrendMode", color: Color.Blue, width: 3, style: LineStyle.Solid);
AddLineSeries(_trendModeSeries);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void OnInit()
{
_indicator = new HtTrendmode();
base.OnInit();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void OnUpdate(UpdateArgs args)
{
double value = SourceInput switch
{
SourceType.Open => GetPrice(PriceType.Open),
SourceType.High => GetPrice(PriceType.High),
SourceType.Low => GetPrice(PriceType.Low),
SourceType.Close => GetPrice(PriceType.Close),
SourceType.HL2 => (GetPrice(PriceType.High) + GetPrice(PriceType.Low)) / 2,
SourceType.HLC3 => (GetPrice(PriceType.High) + GetPrice(PriceType.Low) + GetPrice(PriceType.Close)) / 3,
SourceType.OHLC4 => (GetPrice(PriceType.Open) + GetPrice(PriceType.High) + GetPrice(PriceType.Low) + GetPrice(PriceType.Close)) / 4,
SourceType.HLCC4 => (GetPrice(PriceType.High) + GetPrice(PriceType.Low) + 2 * GetPrice(PriceType.Close)) / 4,
_ => GetPrice(PriceType.Close)
};
bool isNew = args.IsNewBar();
var result = _indicator.Update(new TValue(Time(), value), isNew);
_trendModeSeries.SetValue(result.Value, _indicator.IsHot, ShowColdValues);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private double GetPrice(PriceType priceType)
{
return HistoricalData[0, SeekOriginHistory.End][priceType];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private DateTime Time()
{
return HistoricalData[0, SeekOriginHistory.End].TimeLeft;
}
}