#region Using declarations using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using System.ComponentModel.DataAnnotations; using System.Windows.Media; #endregion //This namespace holds Indicators in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Indicators { public class CumulativeRSI : Indicator { private RSI rsi; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Credit to Larry Connors and his book Short Term Trading Strategies That Work"; Name = "Cumulative RSI"; Calculate = Calculate.OnPriceChange; IsOverlay = false; DisplayInDataBox = true; DrawOnPricePanel = true; PaintPriceMarkers = true; ScaleJustification = ScaleJustification.Right; IsSuspendedWhileInactive = true; AddPlot(new Stroke(Brushes.Yellow, DashStyleHelper.Solid, 3), PlotStyle.Line, "Cumulative RSI"); RSIPeriod = 2; CumulativePeriod = 2; } else if (State == State.DataLoaded) { rsi = RSI(RSIPeriod, 1); } } protected override void OnBarUpdate() { if (CurrentBar < CumulativePeriod) return; double cumulativeRSI = 0; for (int i = 0; i < CumulativePeriod; i++) cumulativeRSI += rsi[i]; Value[0] = cumulativeRSI; } public override string DisplayName { get { return Name; } } #region Properties [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name = "RSI Period", Description = "The period for the RSI calculation", Order = 1, GroupName = "Cumulative RSI")] public int RSIPeriod { get; set; } [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name = "Cumulative Period", Description = "The number of RSI values to add together", Order = 2, GroupName = "Cumulative RSI")] public int CumulativePeriod { get; set; } #endregion } } #region NinjaScript generated code. Neither change nor remove. namespace NinjaTrader.NinjaScript.Indicators { public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase { private CumulativeRSI[] cacheCumulativeRSI; public CumulativeRSI CumulativeRSI(int rSIPeriod, int cumulativePeriod) { return CumulativeRSI(Input, rSIPeriod, cumulativePeriod); } public CumulativeRSI CumulativeRSI(ISeries input, int rSIPeriod, int cumulativePeriod) { if (cacheCumulativeRSI != null) for (int idx = 0; idx < cacheCumulativeRSI.Length; idx++) if (cacheCumulativeRSI[idx] != null && cacheCumulativeRSI[idx].RSIPeriod == rSIPeriod && cacheCumulativeRSI[idx].CumulativePeriod == cumulativePeriod && cacheCumulativeRSI[idx].EqualsInput(input)) return cacheCumulativeRSI[idx]; return CacheIndicator(new CumulativeRSI(){ RSIPeriod = rSIPeriod, CumulativePeriod = cumulativePeriod }, input, ref cacheCumulativeRSI); } } } namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns { public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase { public Indicators.CumulativeRSI CumulativeRSI(int rSIPeriod, int cumulativePeriod) { return indicator.CumulativeRSI(Input, rSIPeriod, cumulativePeriod); } public Indicators.CumulativeRSI CumulativeRSI(ISeries input , int rSIPeriod, int cumulativePeriod) { return indicator.CumulativeRSI(input, rSIPeriod, cumulativePeriod); } } } namespace NinjaTrader.NinjaScript.Strategies { public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.CumulativeRSI CumulativeRSI(int rSIPeriod, int cumulativePeriod) { return indicator.CumulativeRSI(Input, rSIPeriod, cumulativePeriod); } public Indicators.CumulativeRSI CumulativeRSI(ISeries input , int rSIPeriod, int cumulativePeriod) { return indicator.CumulativeRSI(input, rSIPeriod, cumulativePeriod); } } } #endregion