mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-03 19:57:44 +00:00
64 lines
2.0 KiB
C#
64 lines
2.0 KiB
C#
|
|
using System.Drawing;
|
||
|
|
using System.Runtime.CompilerServices;
|
||
|
|
using TradingPlatform.BusinessLayer;
|
||
|
|
|
||
|
|
namespace QuanTAlib;
|
||
|
|
|
||
|
|
[SkipLocalsInit]
|
||
|
|
public sealed class TrixIndicator : Indicator, IWatchlistIndicator
|
||
|
|
{
|
||
|
|
[InputParameter("Period", sortIndex: 1, 1, 1000, 1, 0)]
|
||
|
|
public int Period { get; set; } = 14;
|
||
|
|
|
||
|
|
[IndicatorExtensions.DataSourceInput(sortIndex: 2)]
|
||
|
|
public SourceType Source { get; set; } = SourceType.Close;
|
||
|
|
|
||
|
|
[InputParameter("Show cold values", sortIndex: 21)]
|
||
|
|
public bool ShowColdValues { get; set; } = true;
|
||
|
|
|
||
|
|
private Trix _trix = null!;
|
||
|
|
private readonly LineSeries _series;
|
||
|
|
|
||
|
|
public static int MinHistoryDepths => 0;
|
||
|
|
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
|
||
|
|
|
||
|
|
public override string ShortName => $"TRIX ({Period})";
|
||
|
|
public override string SourceCodeLink => "https://github.com/mihakralj/QuanTAlib/blob/main/lib/oscillators/trix/Trix.Quantower.cs";
|
||
|
|
|
||
|
|
public TrixIndicator()
|
||
|
|
{
|
||
|
|
OnBackGround = true;
|
||
|
|
SeparateWindow = true;
|
||
|
|
Name = "TRIX - Triple Exponential Average Oscillator";
|
||
|
|
Description = "Measures rate of change of a triple-smoothed EMA, filtering noise to reveal underlying momentum";
|
||
|
|
|
||
|
|
_series = new LineSeries("TRIX", Color.Yellow, 2, LineStyle.Solid);
|
||
|
|
AddLineSeries(_series);
|
||
|
|
}
|
||
|
|
|
||
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
|
protected override void OnInit()
|
||
|
|
{
|
||
|
|
_trix = new Trix(Period);
|
||
|
|
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);
|
||
|
|
TValue result = _trix.Update(input, args.IsNewBar());
|
||
|
|
|
||
|
|
if (!_trix.IsHot && !ShowColdValues)
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
_series.SetValue(result.Value);
|
||
|
|
}
|
||
|
|
}
|