#region Using declarations using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Data; using System.Windows.Media; #endregion namespace NinjaTrader.NinjaScript.Indicators { public class NYSECumulativeNewHighsNewLows : Indicator { private const int NewHighsBars = 1; private const int NewLowsBars = 2; private double cumulativeNewHighsLows = 0.0; private Series newHighsLows; private SMA mean; private StdDev stdev; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"NYSE Cumulative New Highs New Lows"; Name = "NYSE Cumulative New Highs New Lows"; Calculate = Calculate.OnBarClose; IsOverlay = false; PaintPriceMarkers = true; ScaleJustification = ScaleJustification.Right; IsSuspendedWhileInactive = true; AddPlot(new Stroke(Brushes.Yellow, 3), PlotStyle.Line, "Z-Score"); } else if (State == State.Configure) { AddDataSeries("FINH", BarsPeriodType.Day, 1); AddDataSeries("FINL", BarsPeriodType.Day, 1); } else if (State == State.DataLoaded) { newHighsLows = new Series(this); mean = SMA(newHighsLows, 252); stdev = StdDev(newHighsLows, 252); } } protected override void OnBarUpdate() { if (BarsInProgress != 0) return; int newHighsBar = BarsArray[NewHighsBars].GetBar(Time[0]); double newHighs = BarsArray[NewHighsBars].GetClose(newHighsBar); int newLowsBar = BarsArray[NewLowsBars].GetBar(Time[0]); double newLows = BarsArray[NewLowsBars].GetClose(newLowsBar); cumulativeNewHighsLows = cumulativeNewHighsLows + (newHighs - newLows); newHighsLows[0] = cumulativeNewHighsLows; double zScore = (cumulativeNewHighsLows - mean[0]) / stdev[0]; Value[0] = zScore; if (zScore > 0) BackBrush = Brushes.LimeGreen; else BackBrush = Brushes.Red; } public override string DisplayName { get { return Name; } } } } #region NinjaScript generated code. Neither change nor remove. namespace NinjaTrader.NinjaScript.Indicators { public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase { private NYSECumulativeNewHighsNewLows[] cacheNYSECumulativeNewHighsNewLows; public NYSECumulativeNewHighsNewLows NYSECumulativeNewHighsNewLows() { return NYSECumulativeNewHighsNewLows(Input); } public NYSECumulativeNewHighsNewLows NYSECumulativeNewHighsNewLows(ISeries input) { if (cacheNYSECumulativeNewHighsNewLows != null) for (int idx = 0; idx < cacheNYSECumulativeNewHighsNewLows.Length; idx++) if (cacheNYSECumulativeNewHighsNewLows[idx] != null && cacheNYSECumulativeNewHighsNewLows[idx].EqualsInput(input)) return cacheNYSECumulativeNewHighsNewLows[idx]; return CacheIndicator(new NYSECumulativeNewHighsNewLows(), input, ref cacheNYSECumulativeNewHighsNewLows); } } } namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns { public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase { public Indicators.NYSECumulativeNewHighsNewLows NYSECumulativeNewHighsNewLows() { return indicator.NYSECumulativeNewHighsNewLows(Input); } public Indicators.NYSECumulativeNewHighsNewLows NYSECumulativeNewHighsNewLows(ISeries input ) { return indicator.NYSECumulativeNewHighsNewLows(input); } } } namespace NinjaTrader.NinjaScript.Strategies { public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.NYSECumulativeNewHighsNewLows NYSECumulativeNewHighsNewLows() { return indicator.NYSECumulativeNewHighsNewLows(Input); } public Indicators.NYSECumulativeNewHighsNewLows NYSECumulativeNewHighsNewLows(ISeries input ) { return indicator.NYSECumulativeNewHighsNewLows(input); } } } #endregion