#region Using declarations using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using System; using System.ComponentModel.DataAnnotations; using System.Windows.Media; #endregion namespace NinjaTrader.NinjaScript.Indicators { [CategoryOrder("ConnorsRSI", 1)] [CategoryOrder("Plots", 2)] [CategoryOrder("Lines", 3)] public class ConnorsRSI : Indicator { private const int RSISmoothing = 1; private RSI rsi; private RSI streakRsi; private ROC roc; private PercentRank percentRankReturns; private Series streak; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Credit to Larry Connors"; Name = "ConnorsRSI"; Calculate = Calculate.OnPriceChange; IsOverlay = false; DisplayInDataBox = true; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = ScaleJustification.Right; IsSuspendedWhileInactive = true; RSIPeriod = 3; StreakRSIPeriod = 2; PercentRankPeriod = 100; AddPlot(new Stroke(Brushes.Yellow, 3), PlotStyle.Line, "ConnorsRSI"); AddLine(new Stroke(Brushes.Red, 3), 75.0, "Upper Level"); AddLine(new Stroke(Brushes.LimeGreen, 3), 25.0, "Lower Level"); } else if (State == State.DataLoaded) { rsi = RSI(RSIPeriod, RSISmoothing); streak = new Series(this, MaximumBarsLookBack.Infinite); streakRsi = RSI(streak, StreakRSIPeriod, RSISmoothing); roc = ROC(1); percentRankReturns = PercentRank(roc, PercentRankPeriod); } } protected override void OnBarUpdate() { if (CurrentBar < 1) return; if (Close[0] > Close[1]) { if (streak[1] > 0) streak[0] = streak[1] + 1; else streak[0] = 1; } else if (Close[0] < Close[1]) { if (streak[1] < 0) streak[0] = streak[1] - 1; else streak[0] = -1; } else streak[0] = 0; if (CurrentBar < Math.Max(RSIPeriod, Math.Max(StreakRSIPeriod, PercentRankPeriod))) return; Value[0] = (rsi[0] + streakRsi[0] + percentRankReturns[0]) / 3; } public override string DisplayName { get { return Name; } } [NinjaScriptProperty] [Display(Name = "RSI Period", GroupName = "ConnorsRSI", Order = 1)] public int RSIPeriod { get; set; } [NinjaScriptProperty] [Display(Name = "Streak RSI Period", GroupName = "ConnorsRSI", Order = 2)] public int StreakRSIPeriod { get; set; } [NinjaScriptProperty] [Display(Name = "Percent Rank Period", GroupName = "ConnorsRSI", Order = 3)] public int PercentRankPeriod { get; set; } } } #region NinjaScript generated code. Neither change nor remove. namespace NinjaTrader.NinjaScript.Indicators { public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase { private ConnorsRSI[] cacheConnorsRSI; public ConnorsRSI ConnorsRSI(int rSIPeriod, int streakRSIPeriod, int percentRankPeriod) { return ConnorsRSI(Input, rSIPeriod, streakRSIPeriod, percentRankPeriod); } public ConnorsRSI ConnorsRSI(ISeries input, int rSIPeriod, int streakRSIPeriod, int percentRankPeriod) { if (cacheConnorsRSI != null) for (int idx = 0; idx < cacheConnorsRSI.Length; idx++) if (cacheConnorsRSI[idx] != null && cacheConnorsRSI[idx].RSIPeriod == rSIPeriod && cacheConnorsRSI[idx].StreakRSIPeriod == streakRSIPeriod && cacheConnorsRSI[idx].PercentRankPeriod == percentRankPeriod && cacheConnorsRSI[idx].EqualsInput(input)) return cacheConnorsRSI[idx]; return CacheIndicator(new ConnorsRSI(){ RSIPeriod = rSIPeriod, StreakRSIPeriod = streakRSIPeriod, PercentRankPeriod = percentRankPeriod }, input, ref cacheConnorsRSI); } } } namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns { public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase { public Indicators.ConnorsRSI ConnorsRSI(int rSIPeriod, int streakRSIPeriod, int percentRankPeriod) { return indicator.ConnorsRSI(Input, rSIPeriod, streakRSIPeriod, percentRankPeriod); } public Indicators.ConnorsRSI ConnorsRSI(ISeries input , int rSIPeriod, int streakRSIPeriod, int percentRankPeriod) { return indicator.ConnorsRSI(input, rSIPeriod, streakRSIPeriod, percentRankPeriod); } } } namespace NinjaTrader.NinjaScript.Strategies { public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.ConnorsRSI ConnorsRSI(int rSIPeriod, int streakRSIPeriod, int percentRankPeriod) { return indicator.ConnorsRSI(Input, rSIPeriod, streakRSIPeriod, percentRankPeriod); } public Indicators.ConnorsRSI ConnorsRSI(ISeries input , int rSIPeriod, int streakRSIPeriod, int percentRankPeriod) { return indicator.ConnorsRSI(input, rSIPeriod, streakRSIPeriod, percentRankPeriod); } } } #endregion