diff --git a/indicators/ThreeCandleReversal.cs b/indicators/ThreeCandleReversal.cs index 43b1621..87edcb0 100644 --- a/indicators/ThreeCandleReversal.cs +++ b/indicators/ThreeCandleReversal.cs @@ -40,8 +40,6 @@ namespace NinjaTrader.NinjaScript.Indicators private List detectedPatterns = new List(); - private int barLookback; - protected override void OnStateChange() { if (State == State.SetDefaults) @@ -62,9 +60,6 @@ namespace NinjaTrader.NinjaScript.Indicators BullishLevelStroke = new Stroke(Brushes.LimeGreen, DashStyleHelper.Solid, 2); BearishLevelStroke = new Stroke(Brushes.Red, DashStyleHelper.Solid, 2); } - else if (State == State.Configure) - { - } if (State == State.DataLoaded) { DetectedPatterns = new Series(this); @@ -76,11 +71,10 @@ namespace NinjaTrader.NinjaScript.Indicators } protected override void OnBarUpdate() - { + { if (CurrentBar < BarLookback + 1) return; - // Real-time processing. for (int i = detectedPatterns.Count - 1; i >= 0; i--) { var pattern = detectedPatterns[i]; @@ -95,10 +89,6 @@ namespace NinjaTrader.NinjaScript.Indicators } } - // Bar close processing. - if (!IsFirstTickOfBar) - return; - DetectedPatterns[0] = null; bool isSwingHigh = true, isSwingLow = true; @@ -161,7 +151,7 @@ namespace NinjaTrader.NinjaScript.Indicators { base.OnRender(chartControl, chartScale); - foreach (var pattern in detectedPatterns) + foreach (var pattern in detectedPatterns.ToArray()) { int startX = chartControl.GetXByBarIndex(ChartBars, pattern.StartBarIndex); int endX = pattern.EndBarIndex == 0 ? ChartPanel.X + ChartPanel.W : chartControl.GetXByBarIndex(ChartBars, pattern.EndBarIndex); @@ -190,11 +180,7 @@ namespace NinjaTrader.NinjaScript.Indicators [Range(1, int.MaxValue), NinjaScriptProperty] [Display(Name = "Bar Lookback", Description = "Number of bars to compare for detecting swing highs / lows", Order = 1, GroupName = "3CR")] - public int BarLookback - { - get { return barLookback; } - set { barLookback = Math.Max(1, value); } // Ensure the value is at least 1 - } + public int BarLookback { get; set; } [NinjaScriptProperty] [XmlIgnore]