#region Using declarations using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Data; using System.Windows.Media; #endregion namespace NinjaTrader.NinjaScript.Indicators { public class NasdaqCumulativeNewHighsNewLows : 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 = @"Nasdaq Cumulative New Highs New Lows"; Name = "Nasdaq 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("FIQH", BarsPeriodType.Day, 1); AddDataSeries("FIQL", 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 NasdaqCumulativeNewHighsNewLows[] cacheNasdaqCumulativeNewHighsNewLows; public NasdaqCumulativeNewHighsNewLows NasdaqCumulativeNewHighsNewLows() { return NasdaqCumulativeNewHighsNewLows(Input); } public NasdaqCumulativeNewHighsNewLows NasdaqCumulativeNewHighsNewLows(ISeries input) { if (cacheNasdaqCumulativeNewHighsNewLows != null) for (int idx = 0; idx < cacheNasdaqCumulativeNewHighsNewLows.Length; idx++) if (cacheNasdaqCumulativeNewHighsNewLows[idx] != null && cacheNasdaqCumulativeNewHighsNewLows[idx].EqualsInput(input)) return cacheNasdaqCumulativeNewHighsNewLows[idx]; return CacheIndicator(new NasdaqCumulativeNewHighsNewLows(), input, ref cacheNasdaqCumulativeNewHighsNewLows); } } } namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns { public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase { public Indicators.NasdaqCumulativeNewHighsNewLows NasdaqCumulativeNewHighsNewLows() { return indicator.NasdaqCumulativeNewHighsNewLows(Input); } public Indicators.NasdaqCumulativeNewHighsNewLows NasdaqCumulativeNewHighsNewLows(ISeries input ) { return indicator.NasdaqCumulativeNewHighsNewLows(input); } } } namespace NinjaTrader.NinjaScript.Strategies { public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.NasdaqCumulativeNewHighsNewLows NasdaqCumulativeNewHighsNewLows() { return indicator.NasdaqCumulativeNewHighsNewLows(Input); } public Indicators.NasdaqCumulativeNewHighsNewLows NasdaqCumulativeNewHighsNewLows(ISeries input ) { return indicator.NasdaqCumulativeNewHighsNewLows(input); } } } #endregion