mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-21 20:18:05 +00:00
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat> Co-authored-by: Warp <agent@warp.dev>
56 lines
1.7 KiB
C#
56 lines
1.7 KiB
C#
using System.Drawing;
|
|
using TradingPlatform.BusinessLayer;
|
|
using static QuanTAlib.IndicatorExtensions;
|
|
|
|
namespace QuanTAlib;
|
|
|
|
/// <summary>
|
|
/// SQRTTRANS (Square Root Transform) Quantower indicator.
|
|
/// Transforms values using the square root function √x for variance stabilization.
|
|
/// </summary>
|
|
public class SqrttransIndicator : Indicator, IWatchlistIndicator
|
|
{
|
|
[DataSourceInput]
|
|
public SourceType Source { get; set; } = SourceType.Close;
|
|
|
|
[InputParameter("Show Cold Values", sortIndex: 100)]
|
|
public bool ShowColdValues { get; set; } = true;
|
|
|
|
private Sqrttrans? _sqrttrans;
|
|
private Func<IHistoryItem, double>? _selector;
|
|
|
|
public int MinHistoryDepths => 1;
|
|
public override string ShortName => "Sqrttrans";
|
|
|
|
public SqrttransIndicator()
|
|
{
|
|
Name = "SQRTTRANS - Square Root Transform";
|
|
Description = "Transforms values using the square root function √x for variance stabilization";
|
|
SeparateWindow = true;
|
|
OnBackGround = true;
|
|
}
|
|
|
|
protected override void OnInit()
|
|
{
|
|
_sqrttrans = new Sqrttrans();
|
|
_selector = Source.GetPriceSelector();
|
|
|
|
AddLineSeries(new LineSeries("Sqrttrans", Color.Blue, 2, LineStyle.Solid));
|
|
}
|
|
|
|
protected override void OnUpdate(UpdateArgs args)
|
|
{
|
|
if (_sqrttrans == null || _selector == null) return;
|
|
|
|
var item = HistoricalData[0, SeekOriginHistory.End];
|
|
double value = _selector(item);
|
|
bool isNew = args.IsNewBar();
|
|
|
|
TValue input = new(item.TimeLeft, value);
|
|
_sqrttrans.Update(input, isNew);
|
|
|
|
bool isHot = _sqrttrans.IsHot;
|
|
|
|
LinesSeries[0].SetValue(_sqrttrans.Last.Value, isHot, ShowColdValues);
|
|
}
|
|
} |