2026-01-24 19:07:52 -08:00
|
|
|
using System.Drawing;
|
|
|
|
|
using TradingPlatform.BusinessLayer;
|
|
|
|
|
|
|
|
|
|
namespace QuanTAlib;
|
|
|
|
|
|
|
|
|
|
public class StbandsIndicator : Indicator, IWatchlistIndicator
|
|
|
|
|
{
|
|
|
|
|
[InputParameter("Period", sortIndex: 1, minimum: 1, maximum: 1000, increment: 1, decimalPlaces: 0)]
|
|
|
|
|
public int Period { get; set; } = 10;
|
|
|
|
|
|
2026-01-27 23:48:33 -08:00
|
|
|
[InputParameter("Multiplier", sortIndex: 2, minimum: 0.001, maximum: 10.0, increment: 0.1, decimalPlaces: 3)]
|
2026-01-24 19:07:52 -08:00
|
|
|
public double Multiplier { get; set; } = 3.0;
|
|
|
|
|
|
|
|
|
|
[InputParameter("Show cold values", sortIndex: 21)]
|
|
|
|
|
public bool ShowColdValues { get; set; } = true;
|
|
|
|
|
|
|
|
|
|
private Stbands? stbands;
|
|
|
|
|
protected LineSeries? UpperSeries;
|
|
|
|
|
protected LineSeries? LowerSeries;
|
|
|
|
|
protected LineSeries? TrendSeries;
|
|
|
|
|
protected LineSeries? WidthSeries;
|
|
|
|
|
|
|
|
|
|
public int MinHistoryDepths => Period;
|
|
|
|
|
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
|
|
|
|
|
|
|
|
|
|
public override string ShortName => $"STBANDS ({Period},{Multiplier:F1})";
|
|
|
|
|
public override string SourceCodeLink => "https://github.com/mihakralj/QuanTAlib/blob/main/lib/channels/stbands/Stbands.cs";
|
|
|
|
|
|
|
|
|
|
public StbandsIndicator()
|
|
|
|
|
{
|
|
|
|
|
Name = "STBANDS - Super Trend Bands";
|
|
|
|
|
Description = "ATR-based dynamic support/resistance channel that adapts to price action with trailing stop-loss levels";
|
|
|
|
|
|
|
|
|
|
UpperSeries = new("Upper", Color.Red, 2, LineStyle.Solid);
|
|
|
|
|
LowerSeries = new("Lower", Color.Green, 2, LineStyle.Solid);
|
|
|
|
|
TrendSeries = new("Trend", Color.Blue, 1, LineStyle.Dot);
|
|
|
|
|
WidthSeries = new("Width", Color.Gray, 1, LineStyle.Dash);
|
|
|
|
|
|
|
|
|
|
AddLineSeries(UpperSeries);
|
|
|
|
|
AddLineSeries(LowerSeries);
|
|
|
|
|
AddLineSeries(TrendSeries);
|
|
|
|
|
AddLineSeries(WidthSeries);
|
|
|
|
|
|
|
|
|
|
SeparateWindow = false;
|
|
|
|
|
OnBackGround = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInit()
|
|
|
|
|
{
|
|
|
|
|
stbands = new(Period, Multiplier);
|
|
|
|
|
base.OnInit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnUpdate(UpdateArgs args)
|
|
|
|
|
{
|
2026-01-24 23:07:09 -08:00
|
|
|
var item = HistoricalData[0, SeekOriginHistory.End];
|
2026-01-24 19:07:52 -08:00
|
|
|
|
|
|
|
|
TBar bar = new(
|
2026-01-24 23:07:09 -08:00
|
|
|
item.TimeLeft,
|
2026-01-24 19:07:52 -08:00
|
|
|
item[PriceType.Open],
|
|
|
|
|
item[PriceType.High],
|
|
|
|
|
item[PriceType.Low],
|
|
|
|
|
item[PriceType.Close],
|
|
|
|
|
item[PriceType.Volume]);
|
|
|
|
|
|
|
|
|
|
stbands!.Update(bar, args.IsNewBar());
|
|
|
|
|
|
|
|
|
|
UpperSeries!.SetValue(stbands.Upper.Value, stbands.IsHot, ShowColdValues);
|
|
|
|
|
LowerSeries!.SetValue(stbands.Lower.Value, stbands.IsHot, ShowColdValues);
|
|
|
|
|
TrendSeries!.SetValue(stbands.Trend.Value, stbands.IsHot, ShowColdValues);
|
|
|
|
|
WidthSeries!.SetValue(stbands.Width.Value, stbands.IsHot, ShowColdValues);
|
|
|
|
|
}
|
2026-01-25 16:01:45 -08:00
|
|
|
}
|