I have created a simple strategy for debugging purposes. All it does is enter a long position when a 50 EMA crosses a 100 EMA. Profit target is set to 4 ticks and stop loss is set to 4 ticks. When I enable the strategy on the chart, my take profits and stop losses are all over the place. I have included screenshots of my strategy settings and some examples where take profit and stop loss does not behave as expected. The distance between horizontal lines on my chart is 1 tick. Tick replay is enabled on my chart. The instrument is ES. The strategy was generated using the strategy builder.
namespace NinjaTrader.NinjaScript.Strategies { public class EMACrossDebug : Strategy { private EMA EMA1; private EMA EMA2; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Strategy here."; Name = "EMACrossDebug"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 1; EntryHandling = EntryHandling.UniqueEntries; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = true; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.High; OrderFillResolutionType = BarsPeriodType.Tick; OrderFillResolutionValue = 1; Slippage = 0; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Day; TraceOrders = false; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 201; // Disable this property for performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = true; } else if (State == State.Configure) { } else if (State == State.DataLoaded) { EMA1 = EMA(Close, 50); EMA2 = EMA(Close, 100); EMA1.Plots[0].Brush = Brushes.Goldenrod; EMA2.Plots[0].Brush = Brushes.OldLace; AddChartIndicator(EMA1); AddChartIndicator(EMA2); SetProfitTarget(@"l", CalculationMode.Ticks, 4); SetStopLoss(@"l", CalculationMode.Ticks, 4, false); } } protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 1) return; // Set 1 if (CrossAbove(EMA1, EMA2, 1)) { EnterLong(Convert.ToInt32(DefaultQuantity), @"l"); } } } }
Take profit and stop loss seem to be working perfectly on 2 and 3 minute charts. It is just the one minute chart that does not seems to work. The screenshots are from the 1 minute chart.
Comment