I've created a simple breakout strategy in the Strategy Builder. I'm trading NQ 09-22, on the 1 minute chart. I've set a 20 tick (5 points) trailing stop loss.
My issue is, most trades are closed instantly (i.e. upon opening) in this strategy. I've used a 3rd party to develop the strategy and there it works fine. It also works in real life settings.
What could be the problem with my code? See below:
namespace NinjaTrader.NinjaScript.Strategies { public class ORBreakoutStrategy : Strategy { private BzvOpeningRange4 BzvOpeningRange41; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Strategy here."; Name = "ORBreakoutStrategy"; Calculate = Calculate.OnEachTick; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.Standard; Slippage = 3; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Gtc; TraceOrders = true; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 20; // Disable this property for performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = true; StopLoss = 20; } else if (State == State.Configure) { } else if (State == State.DataLoaded) { BzvOpeningRange41 = BzvOpeningRange4(Close, @"0930", @"1000", @"1600"); BzvOpeningRange41.Plots[0].Brush = Brushes.LimeGreen; BzvOpeningRange41.Plots[1].Brush = Brushes.OrangeRed; AddChartIndicator(BzvOpeningRange41); SetTrailStop(@"Long", CalculationMode.Ticks, StopLoss, false); } } protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 1) return; // Set 1 if (CrossAbove(Close, BzvOpeningRange41.RangeHighSeries, 1)) { EnterLong(Convert.ToInt32(DefaultQuantity), @"Long"); } } #region Properties [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="StopLoss", Order=1, GroupName="Parameters")] public int StopLoss { get; set; } #endregion } }
Comment