Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Finding the lows of new bars
Collapse
X
-
Hi chatchgo, thank you for your inquiry.
What you're trying to do is entirely possible within NinjaScript. You can access the 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 or CrossBelow.
Lastly, to place a limit order below the low of a bar, you could so something like this:
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.AustinNinjaTrader Customer Service
Comment
-
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 advanceLast edited by chatchgo; 07-02-2009, 08:04 AM.
Comment
-
Chatchgo, have you taken a look at the liveUntilCancelled property of EnterLongLimit?AustinNinjaTrader Customer Service
Comment
-
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 it, and then resubmit a new order. Another option is to just modify the previous order.
I suggest taking a look at IOrders. It allows much greater control over orders, but is a complex subject to get a grasp of.AustinNinjaTrader Customer Service
Comment
-
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...
Comment
-
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:
Code:myShortOrder = [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]EnterShortStop([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], Low[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] + -[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] * TickSize, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Short"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]); CancelOrder(myShortOrder) [/SIZE][/FONT][/SIZE][/FONT]
AustinNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by CortexZenUSA, Today, 12:53 AM
|
0 responses
1 view
0 likes
|
Last Post
by CortexZenUSA
Today, 12:53 AM
|
||
Started by CortexZenUSA, Today, 12:46 AM
|
0 responses
1 view
0 likes
|
Last Post
by CortexZenUSA
Today, 12:46 AM
|
||
Started by usazencortex, Today, 12:43 AM
|
0 responses
5 views
0 likes
|
Last Post
by usazencortex
Today, 12:43 AM
|
||
Started by sidlercom80, 10-28-2023, 08:49 AM
|
168 responses
2,266 views
0 likes
|
Last Post
by sidlercom80
Today, 12:05 AM
|
||
Started by Barry Milan, Yesterday, 10:35 PM
|
3 responses
13 views
0 likes
|
Last Post Yesterday, 11:58 PM |
Comment