How can I best cancel all orders at the end of the day? I am working with GTCs want them pulled at the end of the day?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Best way to cancel all orders at the end of the day?
Collapse
X
-
Best way to cancel all orders at the end of the day?
Hi,
How can I best cancel all orders at the end of the day? I am working with GTCs want them pulled at the end of the day?Tags: None
-
Exit on close is taking care of the positions its just the orders that need to be cancelled. What is the command to pull all orders?
Comment
-
There are two methods to use.
The first one is the supported method -
CancelOrder(IOrder order);
The second is unsupported code -
CancelAllOrders(bool Entries, bool Exits);
Note that with the unsupported code, we would not be able to provide assistance with any debugging or scripting with it.Cal H.NinjaTrader Customer Service
Comment
-
I have 12 possible orders that can exits on close, can I just cancel all of the possibilites or will this generate errors, ie should I do a null check first:
Secondly is there a command to check for the last bar in order to cancel the order, something like:-
If(lastBar)
Comment
-
It is generally good practice to do a null check for your script.
There is no last bar function in NinjaScript as the script would not know what the last bar would be.
This is why I suggested the Time filter. You can use the GetNextBeginEnd() to get the time for when the session ends and use that in your time filter-
GetNextBeginEnd()Cal H.NinjaTrader Customer Service
Comment
-
Thanks that great. I will play round with that. Quick question how do I set max look back bars to infinity?
Comment
-
MaximumBarsLookBack = MaximumBarsLookBack.Infinite
This will go in the Initialize() Method.
http://www.ninjatrader.com/support/h...rslookback.htmCal H.NinjaTrader Customer Service
Comment
-
Im getting an error when I try and and do the check for 5 mins before end of session, if(ToTime(Time[0]) == sessionEnd.AddMinutes(-5)),
Here is the full code snippet.
if(ToTime(Time[0]) == 80500) // Get the end of Session time for when to cancel orders
{
Bars.Session.GetNextBeginEnd(Time[0], out sessionBegin, out sessionEnd);
Print(sessionEnd.AddMinutes(-5));
}
if(ToTime(Time[0]) == sessionEnd.AddMinutes(-5)) // Order Canceling at end 5 mins before end of session.
{
Comment
-
Yup,
private DateTime sessionBegin;
private DateTime sessionEnd;
error is :-
Strategy\PivotTrader2.cs Operator '-' cannot be applied to operands of type 'System.DateTime' and 'int' CS0019 - click for info 149 11
Strategy\PivotTrader2.cs Operator '==' cannot be applied to operands of type 'int' and 'System.DateTime' CS0019 - click for info 154 7
Comment
-
Thanks. I changed that and it compiles fine now but I am getting the below error when I enable to strategy:-
**NT** Error on calling 'OnBarUpdate' method for strategy 'PivotTrader2/25bde81be8aa42489dd9972dff8c0030': You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
I just did a debug with Visual Studio and I can see what is causing the problem.
sessionEnd is coming back with a strange value, see below:
- sessionEnd {01/01/0001 00:00:00} System.DateTime
do you know why this would be happening?Last edited by GKonheiser; 11-24-2013, 01:08 PM.
Comment
-
Hello GKonheiser,
Thank you for your response.
Please add the following to the beginning of the OnBarUpdate() method:
You will need to add an int for the sessionCount in the Variables region as well.Code:if (Bars.FirstBarOfSession && sessionCount < 2) sessionCount++; if (sessionCount < 2) return;
Please let me know if this resolves the error message.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
570 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
330 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
548 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
548 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment