Files
QuanTAlib/quantower/Volatility/JbandsIndicator.cs
T

57 lines
1.7 KiB
C#
Raw Normal View History

2024-10-16 18:28:06 -07:00
using System.Drawing;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
public class JbandsIndicator : Indicator, IWatchlistIndicator
{
2024-11-08 17:11:18 -08:00
[InputParameter("Period", sortIndex: 1, 1, 2000, 1, 0)]
public int Period { get; set; } = 14;
2024-10-16 18:28:06 -07:00
2024-11-08 17:11:18 -08:00
[IndicatorExtensions.DataSourceInput]
2024-10-16 18:28:06 -07:00
public SourceType Source { get; set; } = SourceType.Close;
[InputParameter("vShort", sortIndex: 6, -100, 100, 1, 0)]
public int Phase { get; set; } = 10;
2024-10-21 16:06:47 -07:00
private Jma? jmaUp;
private Jma? jmaLo;
2024-10-16 18:28:06 -07:00
protected LineSeries? UbSeries;
protected LineSeries? LbSeries;
protected string? SourceName;
public static int MinHistoryDepths => 2;
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
public JbandsIndicator()
{
Name = "JBANDS - Mark Jurik's Bands";
Description = "Upper and Lower Bands.";
SeparateWindow = false;
2024-11-06 20:56:32 -08:00
UbSeries = new("UB", color: IndicatorExtensions.Volatility, 2, LineStyle.Solid);
LbSeries = new("LB", color: IndicatorExtensions.Volatility, 2, LineStyle.Solid);
2024-10-16 18:28:06 -07:00
AddLineSeries(UbSeries);
AddLineSeries(LbSeries);
}
protected override void OnInit()
{
2024-11-08 17:11:18 -08:00
jmaUp = new(Period, phase: Phase);
jmaLo = new(Period, phase: Phase);
2024-10-16 18:28:06 -07:00
SourceName = Source.ToString();
base.OnInit();
}
protected override void OnUpdate(UpdateArgs args)
{
2024-10-21 16:06:47 -07:00
TBar input = IndicatorExtensions.GetInputBar(this, args);
jmaUp!.Calc(input.High);
jmaLo!.Calc(input.Low);
2024-10-16 18:28:06 -07:00
2024-10-21 16:06:47 -07:00
UbSeries!.SetValue(jmaUp.UpperBand);
LbSeries!.SetValue(jmaLo.LowerBand);
2024-10-16 18:28:06 -07:00
}
2024-11-08 17:11:18 -08:00
public override string ShortName => $"JBands ({Period}:{Phase})";
2024-10-16 18:28:06 -07:00
}