#region Using declarations using NinjaTrader.Cbi; using System.ComponentModel.DataAnnotations; #endregion namespace NinjaTrader.NinjaScript.Strategies { public class KnifeCatcherBot : Strategy { protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Strategy taken from chapter 3 of Short Term Trading Strategies That Work"; Name = "Knife Catcher 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; BarsToExit = 5; } } protected override void OnBarUpdate() { if (CurrentBar < 3) return; if (Close[0] < Close[1] && Close[1] < Close[2] && Close[2] < Close[3]) EnterLong(); if (BarsSinceEntryExecution() >= BarsToExit) ExitLong(); } public override string DisplayName { get { return Name; } } [NinjaScriptProperty] [Display(Name = "Bars to Exit", GroupName = "Knife Catcher Bot", Order = 1)] public int BarsToExit { get; set; } } }