mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-16 17:48:05 +00:00
Atr, FlowIndicator and fixes
This commit is contained in:
@@ -8,9 +8,12 @@ public class AtrIndicator : Indicator, IWatchlistIndicator
|
||||
[InputParameter("Periods", sortIndex: 1, 1, 2000, 1, 0)]
|
||||
public int Periods { get; set; } = 20;
|
||||
|
||||
[InputParameter("Show cold values", sortIndex: 21)]
|
||||
public bool ShowColdValues { get; set; } = true;
|
||||
|
||||
private Atr? atr;
|
||||
protected LineSeries? AtrSeries;
|
||||
public static int MinHistoryDepths => 2;
|
||||
public int MinHistoryDepths => Math.Max(5, Periods * 2);
|
||||
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
|
||||
|
||||
public AtrIndicator()
|
||||
@@ -19,7 +22,7 @@ public class AtrIndicator : Indicator, IWatchlistIndicator
|
||||
Description = "Measures market volatility by calculating the average range between high and low prices.";
|
||||
SeparateWindow = true;
|
||||
|
||||
AtrSeries = new("ATR", Color.Blue, 2, LineStyle.Solid);
|
||||
AtrSeries = new($"ATR {Periods}", Color.Blue, 2, LineStyle.Solid);
|
||||
AddLineSeries(AtrSeries);
|
||||
}
|
||||
|
||||
@@ -35,7 +38,16 @@ public class AtrIndicator : Indicator, IWatchlistIndicator
|
||||
TValue result = atr!.Calc(input);
|
||||
|
||||
AtrSeries!.SetValue(result.Value);
|
||||
AtrSeries!.SetMarker(0, Color.Transparent); //OnPaintChart draws the line, hidden here
|
||||
|
||||
}
|
||||
|
||||
public override string ShortName => $"ATR ({Periods})";
|
||||
|
||||
public override void OnPaintChart(PaintChartEventArgs args)
|
||||
{
|
||||
base.OnPaintChart(args);
|
||||
this.PaintHLine(args, 0.05, new Pen(Color.DarkRed, width: 2));
|
||||
this.PaintSmoothCurve(args, AtrSeries!, atr!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user