Atr, FlowIndicator and fixes

This commit is contained in:
Miha Kralj
2024-10-21 16:06:47 -07:00
parent fbe4046b5d
commit e3d7cd9896
15 changed files with 335 additions and 189 deletions
+14 -2
View File
@@ -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);
}
}