#region Using declarations using NinjaTrader.NinjaScript.Indicators; using System.ComponentModel.DataAnnotations; #endregion namespace NinjaTrader.NinjaScript.Strategies { public class TwoPeriodRSILows : Strategy { private RSI rsi; private SMA longTermTrend; protected override void OnStateChange() { if (State == State.SetDefaults) { Name = "2-Period RSI Lows"; Description = @"Based on chatper 11 of How Markets Really Work (2012) by Larry Connors"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 1; RSIPeriod = 2; RSISmoothing = 1; RSIEntry = 15; LongTermTrendPeriod = 200; DaysToExit = 5; } else if (State == State.DataLoaded) { rsi = RSI(RSIPeriod, RSISmoothing); longTermTrend = SMA(LongTermTrendPeriod); } } protected override void OnBarUpdate() { if (CurrentBar < RSIPeriod) return; if (rsi[0] < RSIEntry && Close[0] > longTermTrend[0]) EnterLong(); if (BarsSinceEntryExecution(0, "", 0) >= DaysToExit) ExitLong(); } public override string DisplayName { get { return Name; } } [NinjaScriptProperty] [Display(Name = "RSI Period", GroupName = "2-Period RSI Lows", Order = 1)] public int RSIPeriod { get; set; } [NinjaScriptProperty] [Display(Name = "RSI Smoothing", GroupName = "2-Period RSI Lows", Order = 2)] public int RSISmoothing { get; set; } [NinjaScriptProperty] [Display(Name = "RSI Entry", GroupName = "2-Period RSI Lows", Order = 3)] public int RSIEntry { get; set; } [NinjaScriptProperty] [Display(Name = "Long-Term Trend Period", GroupName = "2-Period RSI Lows", Order = 4)] public int LongTermTrendPeriod { get; set; } [NinjaScriptProperty] [Display(Name = "Days to Exit", GroupName = "2-Period RSI Lows", Order = 5)] public int DaysToExit { get; set; } } }