the IOrder variable is set to null after the order is filled. Can you tell me why? When and where is it necessary to set the IOrder variable to null?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Setting IOrder Variable to NULL
Collapse
X
-
Hello,
This is because the logic in OnBarUpdate is using this.
If we look at the example:
OnBarUpdate is variable, this could be on 1 minute data or 1 tick data. To ensure that EnterLong does not get called Multiple times, the if statement checks if there was already an order.Code:private IOrder entryOrder = null; protected override void [B]OnBarUpdate[/B]() { [B]if (entryOrder == null [/B]&& Close[0] > Open[0]) entryOrder = [B]EnterLong[/B](); } protected override void OnOrderUpdate(IOrder order) { if (entryOrder != null && entryOrder == order) { Print(order.ToString()); if (order.OrderState == OrderState.Filled) [B]entryOrder = null;[/B] } }
If there is not a current order or if entryOrder equals null, it sends EnterLong, otherwise does nothing. This just makes only 1 order at a time for the entire life of the order.
This exact scenario may not apply to your script, this is intended to show how to store an IOrder and use it for logic in the entire script or between override methods and also how to check if the filled order was that stored order.
I look forward to being of further assistance.
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
77 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
40 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
63 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
63 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
53 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment