Hi,
I would like to better understand the role of this condition statement included in both @MAX.cs and @MIN.cs.
What are a few examples of situations that demonstrate when CurrentBar < thisBar will equate to 'True'?
Thanks!
HedgePlay
Below is unmodified default NT8 code for @MAX.cs pasted in just to provide a handy context reference.
namespace NinjaTrader.NinjaScript.Indicators { /// <summary> /// The Maximum shows the maximum of the last n bars. /// </summary> public class MAX : Indicator { private int lastBar; private double lastMax; private double runningMax; private int runningBar; private int thisBar; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionMAX; Name = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meMAX; IsOverlay = true; IsSuspendedWhileInactive = true; Period = 14; AddPlot(Brushes.DarkCyan, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meMAX); } else if (State == State.Configure) { lastBar = 0; lastMax = 0; runningMax = 0; runningBar = 0; thisBar = 0; } } protected override void OnBarUpdate() { if (CurrentBar == 0) { runningMax = Input[0]; lastMax = Input[0]; runningBar = 0; lastBar = 0; thisBar = 0; Value[0] = Input[0]; return; } if (CurrentBar - runningBar >= Period || [SIZE=14px][B]CurrentBar < thisBar[/B][/SIZE]) { runningMax = double.MinValue; for (int barsBack = Math.Min(CurrentBar, Period - 1); barsBack > 0; barsBack--) if (Input[barsBack] >= runningMax) { runningMax = Input[barsBack]; runningBar = CurrentBar - barsBack; } } if (thisBar != CurrentBar) { lastMax = runningMax; lastBar = runningBar; thisBar = CurrentBar; } if (Input[0] >= lastMax) { runningMax = Input[0]; runningBar = CurrentBar; } else { runningMax = lastMax; runningBar = lastBar; } Value[0] = runningMax; } #region Properties [Range(1, int.MaxValue), NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)] public int Period { get; set; } #endregion } }
Comment