In the example, the RSI is used to determine an entry and exit. If the RSI is over 70 say, then I enter a short a certain number of ticks above the market for the next bar. However, if I don't get filled, I want to EnterShort (at the market) on the next bar. What appears to be happening, is that the EnterShortLimit is delaying the market entry by an extra bar.
Could someone offer some guidance? For instance, I can run on example data, and see the following in output.
When I comment out the EnterShortLimit line of the code, then the entry is a bar earlier, as expected. It's as if the EnterShortLimit is delaying the entry by a bar, even though that code is not evaluated on Bar#63 as shown in the example output above? Please advise. Thanks.
#region Using declarations using NinjaTrader.Cbi; using NinjaTrader.NinjaScript.Indicators; using System; #endregion //This namespace holds Strategies in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Strategies.MyStrategies { public class RSITest : Strategy { private RSI RSI1; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Strategy here."; Name = "RSITest"; 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; // 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) { RSI1 = RSI(Close, 14, 3); AddChartIndicator(RSI1); } } protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 1) return; // Set 1 Print(Position.MarketPosition.ToString()); if (RSI1.Avg[0] > 70 && RSI1.Avg[1] < 70) { // EnterShort(Convert.ToInt32(DefaultQuantity), ""); Print("TOP, bar#: " + CurrentBar.ToString()); Print("RSI Values: 0: " + RSI1.Avg[0].ToString() + " 1: " + RSI1.Avg[1].ToString() + " 2: " + RSI1.Avg[2].ToString()); EnterShortLimit(0, false, 1, GetCurrentBid() + (1000060 * TickSize), "S"); } if (RSI1.Avg[1] > 70) { Print("BOTTOM, bar#: " + CurrentBar.ToString()); Print("RSI Values: 0: " + RSI1.Avg[0].ToString() + " 1: " + RSI1.Avg[1].ToString() + " 2: " + RSI1.Avg[2].ToString()); EnterShort("S"); } // Set 2 if (RSI1.Avg[0] < 30) { // EnterLong(Convert.ToInt32(DefaultQuantity), ""); EnterLongLimit(0, false, Convert.ToInt32(DefaultQuantity), GetCurrentBid() - (40 * TickSize), ""); } } } }
Comment