Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
1 ATM order at a time, please
Collapse
X
-
Will do, thanks. Wasn't sure if that would mean the close of the bar. I also don't get why if I want to use the open price of the next bar as the entry, why I can't use Open[-1] as an EnterLimit parameter, since market orders let me do that. I would then cancel with if(Close[0] > Open[0] + 2 * TickSize), which I think would cancel the second I'm two ticks away. Oh well.
By the way, when this is all done, I'd like to submit it so that other members can simply grab it and fill in their own parameters. Should make your life easier in the future so please continue to bear with me!
Comment
-
Thanks for offering to share your works, normally this leads to interesting enhancement discussions as well.
You can submit the order at the Open[-1] as this value is simply not know at the time you have to submit the order, the Close of the bar...the next tick is unknown at this point, you could enter at last close price + - an offset to catch it...but could leave you unfilled of course.
Comment
-
Okay, that makes sense. In that case, can I do if(Close[0] > Close [1] + 2 * TickSize)? Using 'Close' makes me think barclose, which I don't want.
Yeah, I have no problem sharing this. I'm sure there are others out there as bad at (or as new to) this as I am. Until an advanced wizard is made, maybe this template can help. There are a few more steps involved (only trade from 'time' - 'time', etc) but I'll submit it to you, if interested, before it's let out with bugs
By the way, if I have EntriesPerDirection set to 1 (or 2, in my case), can I add this strat to all my charts and have it only trade once, no matter how many charts get the signal, or do I still have to use Add() and BarsInProgress = 0, 1, 2?
Thanks.
Comment
-
You can do that code snippet.
For your strategy to only trade once across multiple charts is not possible. You need to use a multi-series indicator with BarsInProgress to achieve that. EntriesPerDirection is a setting for each instance of the strategy running. Running on multiple charts = multiple EntriesPerDirection settings.Josh P.NinjaTrader Customer Service
Comment
-
Question on Entry and CancelOrder logic.
For my signal to work, X has to happen and the bar has to close. I want the entry to be the open of the next bar [-1]. While I CAN do that with market orders, I'm told I can't with limits? I don't follow why it would work for one but not for the other.
Also, for cancel...assuming the open of the current bar is the entry, I want it to cancel the moment it runs (say 4) ticks away. I currently have this:
Entry: entryOrder1 = EnterLongLimit(0, true, DefaultQuantity, Close[0], "Long 1a");
Cancel: Close[0] >= Open[0] + 4 * TickSize
I've noticed, with these snippets, if the signal bar is 4 ticks in length, the order immediately cancels after being placed. Any idea how to avoid that or get the entry I actually want? Close[0] works perfectly in the trail stop snippet as current price but assuming I'm using previous close as entry price (if I have to), if(Close[0] >= Close[0]) --> cancel....looks wrong.
Thanks.
ADDING: Also noticed it's not taking the next good trade if the first would have still been in it, if not for the cancel order...?Last edited by dsraider; 02-05-2010, 09:36 AM.
Comment
-
Dave, a market entry order submitted on this bar's close executes at the next possible trade location, then open tick of the next bar...depending on market dynamics this gives you the open...for limit order's it's different as you have to enter a price point to place the limit at, this value (open of next bar) is unknown at the point of placing the order (this bar's close), thus you can place is as mentioned at an offset to catch it still.
To not cancel right away, wait at least on bar by adding BarsSinceEntry -
I'm not sure I understand you 'added' comment on taking trades - do reset the IOrders as shown if cancelled or filled?
Comment
-
Morning Bertrand,
I hear you on not knowing future price. Only asking again to make certain, especially since it's giving me trouble with my cancels. Unfortunately, the BarsSinceEntry was the only page that comes up blank for me. But, will it say that I can't cancel intrabar? That's something I really have to have. I can't wait for the next.
Output said they were cancelled but it simply missed the next good signal. Has done this a few times now and the only think I THINK I've noticed is that I'd still be in the trade:
Cancelled custom managed order at 2/5/2010 10:44:14 AM: Order='865295cc18c440e3bafbb46c3b56de06/Sim101' Name='Long 1a' State=PendingCancel Instrument='ES 03-10' Action=Buy Limit price=1063 Stop price=0 Quantity=1 Strategy='RaiderTrendStrat' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='865295cc18c440e3bafbb46c3b56de06' Gtd='12/1/2099 12:00:00 AM'
Cancelled custom managed order at 2/5/2010 10:44:14 AM: Order='d39f9242f4b7423caa440e0ea45f682b/Sim101' Name='Long 1b' State=PendingCancel Instrument='ES 03-10' Action=Buy Limit price=1063 Stop price=0 Quantity=1 Strategy='RaiderTrendStrat' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='d39f9242f4b7423caa440e0ea45f682b' Gtd='12/1/2099 12:00:00 AM'
It's now cancelling, what seems to be, at will. Not sure if it was because it didn't fill before bar close. According to my code, though, it should wait until it's cancelled by my IOrder. Could you take a look? It should compile for you.
Thanks,
DaveAttached Files
Comment
-
Light Bulb!
Can I set it to enter if 1 bar back had my signal and then ENterLongLimit at Open[0]? Then I can do CancelOrder if(Close[0] >= Open[0] + 4 * Ticksize) and as long as CalculateOnBarClose is set to false it should cancel the instant price hits +4 ticks and not have to wait for the bar to close, right?
Comment
-
Dave, not sure why you submit to all three bars objects, to get as closely filled to the open as possible to submit to one fast tick chart for example to simulate getting filled intrabar (important if you want to backtest it).
I saw the signals being taken in realtime in my quick test...remember backtesting is disabled by the use of the 'historical'.
You could run on CalculateOnBarClose = false and then submit your orders on the first tick of the bar -
if (FirstTickOfBar)
{
entryorders
}
Basically I would still suggest to simplify rigorously until you're confident the basics work out as expected, then move further forward.
Comment
-
Oh, as far as adding charts are concerned, they get signals at different times. If one isn't already in a trade, I want the signal to be taken.
Everything works fine except for CancelOrder(). I just need to figure out the intrabar cancel madness. Also, I'm sorry but I'm not following you.
If we get a 20/50 cross on the 1 min during the 10:00 bar, I want to let that bar to close and then go long the open of the 10:01 bar (say 1100 ES). Should my limit order not be filled, I want it to cancel once it hits 1101. Will the advice in your last post allow me to do that?
Thanks.
Comment
-
Well, I tried:
if (Position.MarketPosition == MarketPosition.Flat && BarsInProgress == 0)
if(FirstTickOfBar)
{
// Entry Condition: If signal...
if (entryOrder1 == null && entryOrder2 == null && Close[1] > Open[1])
{
entryOrder1 = EnterLongLimit(0, true, DefaultQuantity, Open[0], "Long 1a");
DrawArrowUp("LONG", true, 0, Low[-1] - 12 * TickSize, Color.Green);
entryOrder2 = EnterLongLimit(0, true, DefaultQuantity, Open[0], "Long 1b");
DrawArrowUp("LONG", true, 0, Low[-1] - 12 * TickSize, Color.Green);
}
//Cancel order if price moves four ticks away without filling
else if (entryOrder1 != null && Close[0] >= Open[0] + 4 * TickSize && entryOrder2 != null && Close[0] >= Open[0] + 4 * TickSize)
{
CancelOrder(entryOrder1);
CancelOrder(entryOrder2);
}
AND
if (Position.MarketPosition == MarketPosition.Flat && BarsInProgress == 0)
{
// Entry Condition: If signal..
if (entryOrder1 == null && entryOrder2 == null && Close[1] > Open[1])
if(FirstTickOfBar)
{
entryOrder1 = EnterLongLimit(0, true, DefaultQuantity, Open[0], "Long 1a");
DrawArrowUp("LONG", true, 0, Low[-1] - 12 * TickSize, Color.Green);
entryOrder2 = EnterLongLimit(0, true, DefaultQuantity, Open[0], "Long 1b");
DrawArrowUp("LONG", true, 0, Low[-1] - 12 * TickSize, Color.Green);
}
//Cancel order if price moves four ticks away without filling
else if (entryOrder1 != null && Close[0] >= Open[0] + 4 * TickSize && entryOrder2 != null && Close[0] >= Open[0] + 4 * TickSize)
{
CancelOrder(entryOrder1);
CancelOrder(entryOrder2);
}
Both entered a limit at the right time but only for Long 1a.
Log:
2/5/2010 8:26:43 PM Strategy Error on calling 'OnBarUpdate' method for strategy 'RaiderTrendStrat': Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Output Window:
2/5/2010 8:26:42 PM Entered internal PlaceOrder() method at 2/5/2010 8:26:42 PM: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1090.25 StopPrice=0 SignalName='Long 1a' FromEntrySignal=''
The output window froze there (didn't show target sell/stop cancellation) and the strat wouldn't take new signals. Also, the order didn't cancel after price ran 4+ ticks away or even when barclose was 4+ ticks.
Drinks are on me,
DaveLast edited by dsraider; 02-05-2010, 07:39 PM.
Comment
-
Dave, please add this little snippet to the very beginning of the OnBarUpdate() method:Originally posted by dsraider View PostBoth entered a limit at the right time but only for Long 1a.
Log:
2/5/2010 8:26:43 PM Strategy Error on calling 'OnBarUpdate' method for strategy 'RaiderTrendStrat': Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
The reason for the error is because when this strategy is loaded on a chart it will run through every single bar from left to right until the current bar. On the very first bar, you are trying to access Close[1], which doesn't actually exist because there is only one bar on the chart. The code will back out of the OnBarUpdate() method if there are less than two bars on the chart.Code:OnBarUpdate() { if (CurrentBar < 2) return; }
I have a feeling that should correct your second issue too, but let us know if it doesn't, or if you have any other questions.AustinNinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
20 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
119 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
63 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
41 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
45 views
0 likes
|
Last Post
|

Comment