Files
QuanTAlib/Quantower/Indicators/KAMA_chart.cs
T

56 lines
1.8 KiB
C#
Raw Normal View History

2022-04-23 20:10:30 -07:00
using System.Diagnostics;
using System.Drawing;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
public class KAMA_chart : Indicator
{
#region Parameters
[InputParameter("Smoothing period", 0, 1, 999, 1, 1)]
private int Period = 10;
2022-04-23 20:10:58 -07:00
[InputParameter("Fastest EMA", 1, 1, 999, 1, 1)]
private int Fast = 2;
[InputParameter("Slowest EMA", 2, 1, 999, 1, 1)]
private int Slow = 30;
2022-04-23 20:10:30 -07:00
2022-04-23 20:10:58 -07:00
[InputParameter("Data source", 3, variants: new object[]
2022-04-23 20:10:30 -07:00
{ "Open", 0, "High", 1, "Low", 2, "Close", 3, "HL2", 4, "OC2", 5,
"OHL3", 6, "HLC3", 7, "OHLC4", 8, "Weighted (HLCC4)", 9 })]
private int DataSource = 3;
#endregion Parameters
2022-04-23 20:10:58 -07:00
private TBars bars;
2022-04-23 20:10:30 -07:00
///////
private KAMA_Series indicator;
///////
public KAMA_chart()
{
this.SeparateWindow = false;
this.Name = "KAMA - Kaufman's Adaptive Moving Average";
this.Description = "Kaufman's Adaptive Moving Average description";
this.AddLineSeries("KAMA", Color.RoyalBlue, 3, LineStyle.Solid);
}
protected override void OnInit()
{
2022-04-23 20:10:58 -07:00
this.bars = new();
this.indicator = new(source: bars.Select(this.DataSource), period: this.Period, fast: this.Fast, slow: this.Slow, useNaN: false);
2022-04-23 20:10:30 -07:00
}
protected override void OnUpdate(UpdateArgs args)
{
bool update = !(args.Reason == UpdateReason.NewBar ||
args.Reason == UpdateReason.HistoricalBar);
this.bars.Add(this.Time(), this.GetPrice(PriceType.Open),
this.GetPrice(PriceType.High), this.GetPrice(PriceType.Low),
this.GetPrice(PriceType.Close), this.GetPrice(PriceType.Volume), update);
2022-04-23 20:10:58 -07:00
double result = this.indicator;
2022-04-23 20:10:30 -07:00
this.SetValue(result);
2022-04-23 20:10:58 -07:00
Debug.WriteLine($"{this.indicator[0].v}");
2022-04-23 20:10:30 -07:00
}
}