2026-01-21 17:21:29 -05:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using TradingPlatform.BusinessLayer;
|
|
|
|
|
|
using static QuanTAlib.IndicatorExtensions;
|
|
|
|
|
|
|
|
|
|
|
|
namespace QuanTAlib;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Starchannel: Stoller Average Range Channel - Quantower Indicator Adapter
|
|
|
|
|
|
/// A volatility-based envelope using SMA as the middle line and ATR for band width.
|
|
|
|
|
|
/// Middle = SMA(close, period)
|
|
|
|
|
|
/// Upper = Middle + (multiplier × ATR)
|
|
|
|
|
|
/// Lower = Middle - (multiplier × ATR)
|
|
|
|
|
|
/// ATR uses RMA (Wilder's smoothing) with warmup compensation.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public sealed class StarchannelIndicator : Indicator, IWatchlistIndicator
|
|
|
|
|
|
{
|
2026-02-20 18:44:56 -08:00
|
|
|
|
[InputParameter("SMA Period", sortIndex: 10, minimum: 1, maximum: 500, increment: 1, decimalPlaces: 0)]
|
2026-01-21 17:21:29 -05:00
|
|
|
|
public int Period { get; set; } = 20;
|
|
|
|
|
|
|
2026-02-20 18:44:56 -08:00
|
|
|
|
[InputParameter("ATR Period (0 = same as SMA)", sortIndex: 15, minimum: 0, maximum: 500, increment: 1, decimalPlaces: 0)]
|
|
|
|
|
|
public int AtrPeriod { get; set; } = 0;
|
|
|
|
|
|
|
2026-01-21 17:21:29 -05:00
|
|
|
|
[InputParameter("Multiplier", sortIndex: 20, minimum: 0.1, maximum: 10.0, increment: 0.1, decimalPlaces: 1)]
|
|
|
|
|
|
public double Multiplier { get; set; } = 2.0;
|
|
|
|
|
|
|
|
|
|
|
|
[InputParameter("Show Cold Values", sortIndex: 100)]
|
|
|
|
|
|
public bool ShowColdValues { get; set; } = true;
|
|
|
|
|
|
|
|
|
|
|
|
private Starchannel? _indicator;
|
|
|
|
|
|
|
2026-02-20 18:44:56 -08:00
|
|
|
|
public int MinHistoryDepths => Math.Max(Period, AtrPeriod > 0 ? AtrPeriod : Period);
|
|
|
|
|
|
public override string ShortName => AtrPeriod > 0 && AtrPeriod != Period
|
|
|
|
|
|
? $"Starchannel({Period},{Multiplier},{AtrPeriod})"
|
|
|
|
|
|
: $"Starchannel({Period},{Multiplier})";
|
2026-01-21 17:21:29 -05:00
|
|
|
|
|
|
|
|
|
|
public StarchannelIndicator()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "Starchannel - Stoller Average Range Channel";
|
|
|
|
|
|
Description = "SMA-based channel with ATR-derived band width";
|
|
|
|
|
|
SeparateWindow = false;
|
|
|
|
|
|
OnBackGround = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnInit()
|
|
|
|
|
|
{
|
2026-02-20 18:44:56 -08:00
|
|
|
|
_indicator = new Starchannel(Period, Multiplier, AtrPeriod);
|
2026-01-21 17:21:29 -05:00
|
|
|
|
|
|
|
|
|
|
AddLineSeries(new LineSeries("Middle", Color.DodgerBlue, 2, LineStyle.Solid));
|
|
|
|
|
|
AddLineSeries(new LineSeries("Upper", Color.FromArgb(255, 180, 180), 1, LineStyle.Dash));
|
|
|
|
|
|
AddLineSeries(new LineSeries("Lower", Color.FromArgb(180, 180, 255), 1, LineStyle.Dash));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnUpdate(UpdateArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_indicator is null)
|
2026-01-25 16:01:45 -08:00
|
|
|
|
{
|
2026-01-21 17:21:29 -05:00
|
|
|
|
return;
|
2026-01-25 16:01:45 -08:00
|
|
|
|
}
|
2026-01-21 17:21:29 -05:00
|
|
|
|
|
|
|
|
|
|
var item = HistoricalData[0, SeekOriginHistory.End];
|
|
|
|
|
|
bool isNew = args.IsNewBar();
|
|
|
|
|
|
|
|
|
|
|
|
TBar input = new(
|
|
|
|
|
|
time: item.TimeLeft,
|
|
|
|
|
|
open: item[PriceType.Open],
|
|
|
|
|
|
high: item[PriceType.High],
|
|
|
|
|
|
low: item[PriceType.Low],
|
|
|
|
|
|
close: item[PriceType.Close],
|
|
|
|
|
|
volume: item[PriceType.Volume]
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
_indicator.Update(input, isNew);
|
|
|
|
|
|
|
|
|
|
|
|
bool isHot = _indicator.IsHot;
|
|
|
|
|
|
|
|
|
|
|
|
LinesSeries[0].SetValue(_indicator.Last.Value, isHot, ShowColdValues);
|
|
|
|
|
|
LinesSeries[1].SetValue(_indicator.Upper.Value, isHot, ShowColdValues);
|
|
|
|
|
|
LinesSeries[2].SetValue(_indicator.Lower.Value, isHot, ShowColdValues);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|