#region Using declarations using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.NinjaScript.Indicators; using System.ComponentModel.DataAnnotations; #endregion namespace NinjaTrader.NinjaScript.Strategies { public class TRINBot : Strategy { private RSI rsi; private SMA longTermTrend; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Taken from chapter 12 of Short Term Trading Strategies That Work"; Name = "TRIN Bot"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.Standard; Slippage = 0; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Gtc; TraceOrders = false; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 20; IsInstantiatedOnEachOptimizationIteration = true; LongTermTrendPeriod = 200; RSIPeriod = 2; RSISmoothing = 1; } else if (State == State.Configure) { AddDataSeries("^TRIN", BarsPeriodType.Day, 1); } else if (State == State.DataLoaded) { rsi = RSI(RSIPeriod, RSISmoothing); longTermTrend = SMA(LongTermTrendPeriod); } } protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[1] < 2) return; if (CurrentBar < LongTermTrendPeriod) return; if (Close[0] > longTermTrend[0] && rsi[0] < 50) { if (Closes[1][0] > 1.0 && Closes[1][1] > 1.0 && Closes[1][2] > 1.0) EnterLong(); } else if (rsi[0] > 65) ExitLong(); } public override string DisplayName { get { return Name; } } [NinjaScriptProperty] [Display(Name = "Long-Term Trend Period", GroupName = "TRIN Bot", Order = 1)] public int LongTermTrendPeriod { get; set; } [NinjaScriptProperty] [Display(Name = "RSI Period", GroupName = "TRIN Bot", Order = 2)] public int RSIPeriod { get; set; } [NinjaScriptProperty] [Display(Name = "RSI Smoothing", GroupName = "TRIN Bot", Order = 3)] public int RSISmoothing { get; set; } } }