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
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
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:
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 trades4x, Today, 01:25 PM
|
2 responses
11 views
0 likes
|
Last Post
by trades4x
Today, 08:26 PM
|
||
Started by ZWallStreet, Today, 07:55 PM
|
0 responses
14 views
0 likes
|
Last Post
by ZWallStreet
Today, 07:55 PM
|
||
Started by ark321, Today, 07:30 PM
|
0 responses
4 views
0 likes
|
Last Post
by ark321
Today, 07:30 PM
|
||
Started by olisav57, Today, 07:25 PM
|
0 responses
6 views
0 likes
|
Last Post
by olisav57
Today, 07:25 PM
|
||
Started by duck_CA, 08-06-2024, 05:24 PM
|
4 responses
74 views
0 likes
|
Last Post
by duck_CA
Today, 06:45 PM
|
Comment