View Full Version : Buy on second bar as it breaks first pls help
gamblor
02-15-2008, 12:31 PM
simple i want to enter long as the second bar breaks the first. 5 min chart at the open.
this should be really simple and i just cant figure it out.
if (Close[0] > High[1])
;
{
EnterLong(DefaultQuantity, "");
on the backtest settings window if i try 0 bars required it doesnt get me in and if i try 1 bar required it gets me in on the third bar at some odd price.
thanks in advance
NinjaTrader_Ray
02-15-2008, 12:36 PM
Please review this reference sample.
http://www.ninjatrader-support.com/vb/showthread.php?t=3223
gamblor
02-15-2008, 01:24 PM
this is better, but
changed the code to look like this, i just put 0's as the low number:
// Stores the highest high from the first 30 bars
if (Bars.BarsSinceSession < 0 && High[0] > highestHigh)
highestHigh = High[0];
// Entry Condition: Submit a buy stop order one tick above the first 30 bar high. Cancel if not filled within 10 bars.
if (Bars.BarsSinceSession > 0 && Bars.BarsSinceSession < 40)
so, its still getting me in way late, in this case RNR today on a 5 min chart gets me in on the 5th bar even though the second broke the first.
sorry man am not a programmer, i cant understand what numbers NJ is referencing.
NinjaTrader_Ray
02-15-2008, 03:01 PM
Unfortunately you need to be somewhat of a programmer to work your way through this.
scriabinop23
02-15-2008, 06:30 PM
simple i want to enter long as the second bar breaks the first. 5 min chart at the open.
this should be really simple and i just cant figure it out.
if (Close[0] > High[1])
;
{
EnterLong(DefaultQuantity, "");
on the backtest settings window if i try 0 bars required it doesnt get me in and if i try 1 bar required it gets me in on the third bar at some odd price.
thanks in advance
Have you tried this?
if (Bars.BarsSinceSession == 1
&& Open[0] >= Close[1]
&& Close[1] > Open[1])
EnterLong();}
}
Set your session to begin 5 minutes before you actually want it to start, ie if your session is 9:30am, make it 9:25am. That way Bar 0 is 9:30am, and Bar 1 is 9:35. This enters only on the 2nd bar of the session.
And make sure CalculateOnBarClose = false;
gamblor
02-15-2008, 10:56 PM
thanks ray guess am an idiot. dont understand why this sample doesnt work with a couple of mods.
if i got this right, the second statement that says it stores the highest high off the 30 bars can be changed to:
if (Bars.BarsSinceSession < 0 && High[0] > highestHigh)
all i did is tell it to use to use the first bar to set the highesthigh
then:
if (Bars.BarsSinceSession > 1 && Bars.BarsSinceSession < 40)
should get me in on the next bar.
but it doesnt it takes me in on the 5th bar of this chart, i can post a chart if you'd like somewhere.
why is it waiting that long? its clear to me that the 5th bar is breaking the first 5 min high, but that already happened on the second bar and thats where it should be going in.
think i'll leave for now... long weekend and am going on holidays for a while next week. i'll ask again then.
scriabinop23: thanks man, i'll look into your post tomorrow, maybe thats the solution.... thanks for helping any help is greatly appreciated.
:)
NinjaTrader_Josh
02-16-2008, 12:51 AM
Hi gamblor,
Please debug your code per this tip: http://www.ninjatrader-support.com/vb/showthread.php?t=3418
scriabinop23
02-16-2008, 08:38 AM
Here's some other ideas for you.
Bars.BarsSinceSession can never be below 0, so that logic is flawed in itself. Do a
Print(Time[0] + " " + Bars.BarsSinceSession + " O: " +Open[0] + " C-1:" +Close[1]) in onbarupdate and you'll see that the first bar of a session is actually bar 0.
High[0] when at Bars.BarsSinceSession == 0 is actually the high of the previous day's last bar. Thats why you want to start your session 5 minutes early.
There's a built in function (indicator) to find the current session's high.
Use:
CurrentDayOHL().CurrentHigh[0]
Additionally, you can check the previous session's high:
PriorDayOHLC().PriorHigh[0]
That will tell you, effective the most recent bar, what the current high is.