#region Using declarations using NinjaTrader.Cbi; using NinjaTrader.NinjaScript.Indicators; #endregion namespace NinjaTrader.NinjaScript.Strategies { public class InternalBarStrengthBot : Strategy { private InternalBarStrength ibs; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Long only bot which bases trades on internal bar strength"; Name = "Internal Bar Strength 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; } else if (State == State.DataLoaded) { ibs = InternalBarStrength(); } } protected override void OnBarUpdate() { if (CurrentBar < BarsRequiredToTrade) return; if (ibs[0] < 0.2) EnterLong(); else if (ibs[0] > 0.8 && Position.MarketPosition == MarketPosition.Long) ExitLong(); } public override string DisplayName { get { return Name; } } } }