The best way to look into this would be to set up a test strategy as I have attached where we look for a certain bar to enter, or use a certain bar to submit the order in question. This helps to make the tests more manageable without needing the ~1200 lines of code to reproduce the issue.
Could you modify the strategy I provided so it includes the prints I used and also modify it so only the orders in question are generated?
Print this bar and next bar:
Print(""); Print(String.Format("This bar: Time: {0} Open: {1} High: {2} Low: {3} Close: {4}", Bars.GetTime(CurrentBar), Bars.GetOpen(CurrentBar), Bars.GetHigh(CurrentBar), Bars.GetLow(CurrentBar), Bars.GetClose(CurrentBar))); Print(String.Format("Next bar: Time: {0} Open: {1} High: {2} Low: {3} Close: {4}", Bars.GetTime(CurrentBar+1), Bars.GetOpen(CurrentBar+1), Bars.GetHigh(CurrentBar+1), Bars.GetLow(CurrentBar+1), Bars.GetClose(CurrentBar+1))); Print("");
DateTime _Date = new DateTime(2020, 4, 23, 00, 00, 00); DateTime _CurrentDate = Time[0].Date; if (_CurrentDate == _Date && High[0] == 2801.50 && Low[0] == 2793.50) { ShortEntryPrice = Low[0] - 2*TickSize; ShortStopLossPrice = High[0] + 2*TickSize; SE = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopLimit, 1, ShortEntryPrice, ShortEntryPrice, string.Empty, "Short Entry"); }
Exporting data - https://ninjatrader.com/support/help...?exporting.htm
I can note that you are using BarsAgo 1 references in your script when processing historical data. Please note that historical processing follows Calculate.OnBarClose behaviors since there is no intrabar movement. BarsAgo 1 references would be used to reference the close of a bar when processing realtime data with Calculate.OnPriceChange or Calculate.OnEachTick and using IsFirstTickOfBar to identify when we are processing a new bar. (Bar closures are signaled by the first tick of a new bar.) The example below can help illustrate.
https://ninjatrader.com/support/help...either_cal.htm
I look forward to assisting.
Leave a comment: