#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 { public class ConnorsRSI : Indicator { 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.OnBarClose; IsOverlay = false; DisplayInDataBox = true; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = ScaleJustification.Right; IsSuspendedWhileInactive = true; RSIPeriod = 3; RSISmoothing = 1; StreakRSIPeriod = 2; StreakRSISmoothing = 1; PercentRankPeriod = 100; AddPlot(new Stroke(Brushes.Yellow, 3), PlotStyle.Line, "ConnorsRSI"); } else if (State == State.DataLoaded) { rsi = RSI(RSIPeriod, RSISmoothing); streak = new Series(this, MaximumBarsLookBack.Infinite); streakRsi = RSI(streak, StreakRSIPeriod, StreakRSISmoothing); 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 = "RSI Smoothing", GroupName = "ConnorsRSI", Order = 2)] public int RSISmoothing { get; set; } [NinjaScriptProperty] [Display(Name = "Streak RSI Period", GroupName = "ConnorsRSI", Order = 3)] public int StreakRSIPeriod { get; set; } [NinjaScriptProperty] [Display(Name = "Streak RSI Smoothing", GroupName = "ConnorsRSI", Order = 4)] public int StreakRSISmoothing { get; set; } [NinjaScriptProperty] [Display(Name = "Percent Rank Period", GroupName = "ConnorsRSI", Order = 5)] 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 rSISmoothing, int streakRSIPeriod, int streakRSISmoothing, int percentRankPeriod) { return ConnorsRSI(Input, rSIPeriod, rSISmoothing, streakRSIPeriod, streakRSISmoothing, percentRankPeriod); } public ConnorsRSI ConnorsRSI(ISeries input, int rSIPeriod, int rSISmoothing, int streakRSIPeriod, int streakRSISmoothing, int percentRankPeriod) { if (cacheConnorsRSI != null) for (int idx = 0; idx < cacheConnorsRSI.Length; idx++) if (cacheConnorsRSI[idx] != null && cacheConnorsRSI[idx].RSIPeriod == rSIPeriod && cacheConnorsRSI[idx].RSISmoothing == rSISmoothing && cacheConnorsRSI[idx].StreakRSIPeriod == streakRSIPeriod && cacheConnorsRSI[idx].StreakRSISmoothing == streakRSISmoothing && cacheConnorsRSI[idx].PercentRankPeriod == percentRankPeriod && cacheConnorsRSI[idx].EqualsInput(input)) return cacheConnorsRSI[idx]; return CacheIndicator(new ConnorsRSI(){ RSIPeriod = rSIPeriod, RSISmoothing = rSISmoothing, StreakRSIPeriod = streakRSIPeriod, StreakRSISmoothing = streakRSISmoothing, PercentRankPeriod = percentRankPeriod }, input, ref cacheConnorsRSI); } } } namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns { public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase { public Indicators.ConnorsRSI ConnorsRSI(int rSIPeriod, int rSISmoothing, int streakRSIPeriod, int streakRSISmoothing, int percentRankPeriod) { return indicator.ConnorsRSI(Input, rSIPeriod, rSISmoothing, streakRSIPeriod, streakRSISmoothing, percentRankPeriod); } public Indicators.ConnorsRSI ConnorsRSI(ISeries input , int rSIPeriod, int rSISmoothing, int streakRSIPeriod, int streakRSISmoothing, int percentRankPeriod) { return indicator.ConnorsRSI(input, rSIPeriod, rSISmoothing, streakRSIPeriod, streakRSISmoothing, percentRankPeriod); } } } namespace NinjaTrader.NinjaScript.Strategies { public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.ConnorsRSI ConnorsRSI(int rSIPeriod, int rSISmoothing, int streakRSIPeriod, int streakRSISmoothing, int percentRankPeriod) { return indicator.ConnorsRSI(Input, rSIPeriod, rSISmoothing, streakRSIPeriod, streakRSISmoothing, percentRankPeriod); } public Indicators.ConnorsRSI ConnorsRSI(ISeries input , int rSIPeriod, int rSISmoothing, int streakRSIPeriod, int streakRSISmoothing, int percentRankPeriod) { return indicator.ConnorsRSI(input, rSIPeriod, rSISmoothing, streakRSIPeriod, streakRSISmoothing, percentRankPeriod); } } } #endregion