I'm testing long entries on ES 5 minute bars as follows:
1. Record the open of the first bar of the day (8:30am-8:35am) and refer to it as "OpenPrice"
2. At the close of the second bar of the day (8:40am) go long if:
a) The low of bar 2 is greater than OpenPrice
b) The 5 bar RSI indicator is below 50 OR both the close is greater than the previous bar close and the close is greater than previous bar close AND the close is greater than close 2 bars ago AND the daily close is less than the daily close 2 bars ago.
For item 1 above I used the following code to store the open of the first bar of the day to "OpenPrice"
protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 0) return; if (Times[0][0].TimeOfDay == new TimeSpan(08,30,0)) { OpenPrice = Open[0]; return;
// Set 1 if ( // Condition group 1 ((Times[0][0].TimeOfDay == new TimeSpan(8, 40, 0)) && (Low[0] > OpenPrice) && (RSI1.Avg[0] < 50)) // // Condition group 2 || ((Times[0][0].TimeOfDay == new TimeSpan(8, 40, 0)) && (Low[0] > OpenPrice) && (Close[0] > Close[1]) && (Close[0] > Close[2]) && (Closes[1][0] < Closes[1][2])) ) { EnterLong(Convert.ToInt32(DefaultQuantity), "");
if (BarsSinceEntryExecution() >= exit5_X) { ExitLong(); }
OpenPrice = 4000; exit5_X = 5; } else if (State == State.Configure) { } else if (State == State.DataLoaded) { RSI1 = RSI(Close, 5, 1); } } [NinjaScriptProperty] public int exit5_X { get; set; } protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 0) return; if (Times[0][0].TimeOfDay == new TimeSpan(08,30,0)) { OpenPrice = Open[0]; return; // Set 1 if ( // Condition group 1 ((Times[0][0].TimeOfDay == new TimeSpan(8, 40, 0)) && (Low[0] > OpenPrice) && (RSI1.Avg[0] < 50)) // // Condition group 2 || ((Times[0][0].TimeOfDay == new TimeSpan(8, 40, 0)) && (Low[0] > OpenPrice) && (Close[0] > Close[1]) && (Close[0] > Close[2]) && (Closes[1][0] < Closes[1][2])) ) { EnterLong(Convert.ToInt32(DefaultQuantity), ""); } if (BarsSinceEntryExecution() >= exit5_X) { ExitLong(); } } }
Thanks,
Ben
Comment