#region Using declarations using NinjaTrader.Cbi; using NinjaTrader.NinjaScript.Indicators; #endregion namespace NinjaTrader.NinjaScript.Strategies { public class RSIDivergenceBot : Strategy { private RSI rsi; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Simple strategy based on RSI divergence"; Name = "RSI Divergence Bot"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = false; 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; } else if (State == State.DataLoaded) { rsi = RSI(14, 3); } } protected override void OnBarUpdate() { if (CurrentBar < BarsRequiredToTrade) return; if (rsi[0] > rsi[5] && Close[0] < Close[5]) EnterLong(); if (Position.MarketPosition == MarketPosition.Long && rsi[0] > 70.0) ExitLong(); } public override string DisplayName { get { return Name; } } } }