From 3b71ac70c8a57c2550227035a8b82990d1d7ea1d Mon Sep 17 00:00:00 2001 From: Miha Kralj Date: Mon, 17 Apr 2023 16:54:23 -0700 Subject: [PATCH] Update 2MASlope_chart.cs --- Indicators/Charts/2MASlope_chart.cs | 22 +++++++++++++++------- Indicators/Charts/TrailingStop.cs | 1 - 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Indicators/Charts/2MASlope_chart.cs b/Indicators/Charts/2MASlope_chart.cs index 2c52110e..4f65c53e 100644 --- a/Indicators/Charts/2MASlope_chart.cs +++ b/Indicators/Charts/2MASlope_chart.cs @@ -50,6 +50,8 @@ public class MovingAverageSlope_chart : Indicator { private TSeries MA1, MA2; private LINREG_Series sMA1, sMA2; private CROSS_Series sig1, sig2; + + private bool inLong, inShort; /////// public MovingAverageSlope_chart() { @@ -240,31 +242,37 @@ public class MovingAverageSlope_chart : Indicator { this.LinesSeries[1].SetMarker(0,s2Color); if (sig1[^1].v > 0 || sig2[^1].v > 0) { - if (sMA1[^1].v >= 0 && sMA2[^1].v >= 0) + if (sMA1[^1].v >= 0 && sMA2[^1].v >= 0 && LongTrades) { + inLong = true; this.BeginCloud(0, 1, Color.FromArgb(127, Color.DarkGreen)); this.LinesSeries[(this.MA1[^1].v < this.MA2[^1].v)? 0 : 1 ].SetMarker(0, new IndicatorLineMarker(Color.LimeGreen, bottomIcon: IndicatorLineMarkerIconType.UpArrow)); } else { this.EndCloud(0, 1, Color.Empty); - this.LinesSeries[(this.MA1[^1].v < this.MA2[^1].v) ? 1 : 0].SetMarker(1, new IndicatorLineMarker(Color.OrangeRed, upperIcon: IndicatorLineMarkerIconType.DownArrow)); + if (inShort) + { + this.LinesSeries[(this.MA1[^1].v < this.MA2[^1].v) ? 1 : 0].SetMarker(1, new IndicatorLineMarker(Color.OrangeRed, upperIcon: IndicatorLineMarkerIconType.DownArrow)); + inShort = false; + } } - } if (sig1[^1].v < 0 || sig2[^1].v < 0) { - if (sMA1[^1].v <= 0 && sMA2[^1].v <= 0) + if (sMA1[^1].v <= 0 && sMA2[^1].v <= 0 && ShortTrades) { + inShort = true; this.BeginCloud(0, 1, Color.FromArgb(100, Color.Red)); this.LinesSeries[(this.MA1[^1].v > this.MA2[^1].v) ? 0 : 1].SetMarker(0, new IndicatorLineMarker(Color.OrangeRed, upperIcon: IndicatorLineMarkerIconType.UpArrow)); - } else { this.EndCloud(0, 1, Color.Empty); - this.LinesSeries[(this.MA1[^1].v > this.MA2[^1].v)?1:0].SetMarker(1, new IndicatorLineMarker(Color.LimeGreen, bottomIcon: IndicatorLineMarkerIconType.DownArrow)); + if (inLong) { + LinesSeries[(this.MA1[^1].v > this.MA2[^1].v)?1:0].SetMarker(1, new IndicatorLineMarker(Color.LimeGreen, bottomIcon: IndicatorLineMarkerIconType.DownArrow)); + inLong = false; + } } } - } public override void OnPaintChart(PaintChartEventArgs args) { base.OnPaintChart(args); diff --git a/Indicators/Charts/TrailingStop.cs b/Indicators/Charts/TrailingStop.cs index 3413ccb5..2f20542e 100644 --- a/Indicators/Charts/TrailingStop.cs +++ b/Indicators/Charts/TrailingStop.cs @@ -90,7 +90,6 @@ public class TrailingStop_chart : Indicator { this.SetValue(_ratchetL, lineIndex: 1); this.SetValue(_tslineS, lineIndex: 2); this.SetValue(_ratchetS, lineIndex: 3); - } public override void OnPaintChart(PaintChartEventArgs args) {