View Full Version : Finding the lows of new bars
chatchgo
07-02-2009, 06:35 AM
Is there a way for NT to find the lows of each 1 min bar, then placing a limit order below those bars after a crossover?
chatchgo
07-02-2009, 07:13 AM
I guess Im looking for a live until cancelled help, taking a look at it now...
NinjaTrader_Josh
07-02-2009, 07:31 AM
chatchgo,
Sure. What is your question for using liveUntilCancelled?
You can check for lower lows through the use of MIN(Low, 10)[0] for instance. That would give you the lowest low for a 10 bar period.
chatchgo
07-02-2009, 07:42 AM
Hey Josh,
Im trying to get NT to enter a limit order 2 ticks below the low of every bar after a crossover? Im not too sure how to program this, as Im new to writing programs :o
Thanks in advance
NinjaTrader_Austin
07-02-2009, 07:48 AM
Hi chatchgo, thank you for your inquiry.
What you're trying to do is entirely possible within NinjaScript. You can access the low (http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?Low) of each bar by referencing Low[x], where 'x' is the number of bars back. So if you want the low of the current bar, just take a look at Low[0].
The next step would be to check for crossovers, which you can do with either CrossAbove (http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?CrossAbove)or CrossBelow (http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?CrossBelow).
Lastly, to place a limit order below the low of a bar, you could so something like this:
EnterLongLimit (http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?EnterLongLimit)(Low[0] - 2*TickSize, "buy below the low"). That would place a buy limit order at two ticks below the low of the current bar.
Hopefully this gets you going in the right direction, but let us know if you're still having problems.
chatchgo
07-02-2009, 07:53 AM
Thx Austin, Ive gotten that far, now I need the order to stay live until filled...b/c everytime that order isnt filled it cancels itself and price runs away. I need the order to stay live, and keep trailing 2 ticks below the low of the future bar. I tried Low (-1), but that doesn't seem to work.
Thanks in advance
NinjaTrader_Austin
07-02-2009, 08:14 AM
Chatchgo, have you taken a look at the liveUntilCancelled property of EnterLongLimit (http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?EnterLongLimit)?
chatchgo
07-02-2009, 08:50 AM
Im not sure what to write in for the bool entry, can u show me an example possibly of a liveuntilcancelled entry?
NinjaTrader_Austin
07-02-2009, 09:01 AM
Sure thing, EnterLongLimit(0, true, DefaultQuantity, LimitPrice, "buy signal"), where LimitPrice is your limit price, and "buy signal" is the signal name.
The "true" is all you need to set liveUntilCancelled.
chatchgo
07-02-2009, 09:28 AM
OK thx austin...that got the ball rolling. Now that the order stays live, how do I look for the next bar's low -2 ticks
NinjaTrader_Austin
07-02-2009, 09:46 AM
Chatchgo, I can outline for you what you can do to accomplish this, but I can't write all the code.
Ok, so when the order is first placed, all is fine and good.
The next bar (now the current bar) comes and the order is still active, yet the low of the current bar has changed.
This is where you have a few options. You can add some new logic to the OnBarUpdate section checking to see whether or not the order has been filled. If it hasn't, you can cancel (http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?CancelOrder)it, and then resubmit a new order. Another option is to just modify the previous order.
I suggest taking a look at IOrder (http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?IOrder)s. It allows much greater control over orders, but is a complex subject to get a grasp of.
chatchgo
07-02-2009, 10:12 AM
EnterShortStop(0, true, 1, Low[0] + -2 * TickSize, "Short");
DrawVerticalLine("My vertical line" + CurrentBar, 0, Color.Red);
if (CurrentBar > 0 + 5)
CancelOrder ("Short");
Im here in the process now Austin. But I can't figure out what name to call when I cancel order?? I tried to set a name to the the original entry order
(myEntryOrder = EnterLongLimit(0, true, 1, Low[0], "Long Entry");
But i get error on generating strategy...
NinjaTrader_Austin
07-02-2009, 11:00 AM
Chatchgo, I'll investigate this further and let you know.
NinjaTrader_Austin
07-02-2009, 11:23 AM
When calling CancelOrder, you need to specify the IOrder object, not a string value.
In your case, you could change your EnterShortStop to an IOrder object, and then cancel that.
Ex:
myShortOrder = EnterShortStop(0, true, 1, Low[0] + -2 * TickSize, "Short");
CancelOrder(myShortOrder)