mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-02 11:37:42 +00:00
a9e72dae0d
- Updated Codacy instructions to streamline usage guidelines. - Refactored Bbands class to utilize ArrayPool for memory management, preventing stack overflow on large series. - Changed Fcb class to use long for monotonic deques to avoid truncation issues. - Enhanced Kchannel class to ensure safe defaults for non-finite values. - Improved Maenv class to prevent double-priming during calculations. - Modified Mmchannel class to ensure non-negative buffer indices and removed unnecessary state tracking. - Updated Pchannel class to correctly reference IsHot state. - Refined Regchannel class to avoid double-processing during calculations. - Enhanced Starchannel class to sanitize non-finite values during calculations. - Adjusted Stbands.Quantower.cs to allow finer control over multiplier precision. - Updated Ubands class to only update last valid values on new bars. - Modified Uchannel.Quantower.cs to allow for finer multiplier precision. - Enhanced Vwapbands classes to include standard deviation calculations and ensure consistent array lengths. - Refactored Vwapsd classes to include standard deviation outputs and ensure consistent array lengths. - Updated MonotonicDeque to use long for indices to prevent overflow. - Improved Mdape class to handle zero actual values with a substitute value for error calculation. - Enhanced Rae class to ensure correct state management during updates. - Refined Wmape class to simplify the logic for finding last valid actual and predicted values. - Updated Cmf.Quantower classes to ensure MinHistoryDepths reflects the current period.
74 lines
2.6 KiB
C#
74 lines
2.6 KiB
C#
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;
|
|
|
|
[InputParameter("Multiplier", sortIndex: 2, minimum: 0.001, maximum: 10.0, increment: 0.1, decimalPlaces: 3)]
|
|
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)
|
|
{
|
|
var item = HistoricalData[0, SeekOriginHistory.End];
|
|
|
|
TBar bar = new(
|
|
item.TimeLeft,
|
|
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);
|
|
}
|
|
}
|