Suppose I get a signal and EnterLong() in OnBarUpdate. Code in my OnExecution handler will fire. Is it true that as soon as EnterLong() is called, the OnExecution handler runs and completes and then returns to execute the line of code following EnterLong() in OnBarUpdate?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Code Execution Sequence
Collapse
X
-
Code Execution Sequence
I would like to clarify code execution between the OnBarUpdate and OnExecution event handlers.
Suppose I get a signal and EnterLong() in OnBarUpdate. Code in my OnExecution handler will fire. Is it true that as soon as EnterLong() is called, the OnExecution handler runs and completes and then returns to execute the line of code following EnterLong() in OnBarUpdate?Tags: None
-
Hello reynoldsn,
Thank you for your inquiry.
The OnExecution() method runs on an incoming execution (or fill) of an order. It is entirely possible for other code to execute before OnExecution() is even called when using EnterLong(). Here's a simple example to test this out:
In my output window:Code:private int realTimeTicks = 0; protected override void OnBarUpdate() { if (realTimeTicks == 150) { EnterLong(); Print("EnterLong() called!"); } if (!Historical) { realTimeTicks++; Print(String.Format("{0} ticks", realTimeTicks)); } } protected override void OnExecution(IExecution execution) { if (!Historical) { Print("OnExecution() called!"); } }
As you can see, ticks were still printing out after we called EnterLong() and before OnExecution() was called.Code:EnterLong() called! 151 ticks 152 ticks 153 ticks 154 ticks 155 ticks 156 ticks 157 ticks 158 ticks 159 ticks 160 ticks 161 ticks 162 ticks 163 ticks 164 ticks 165 ticks 166 ticks 167 ticks 168 ticks 169 ticks 170 ticks 171 ticks 172 ticks 173 ticks 174 ticks 175 ticks 176 ticks 177 ticks 178 ticks 179 ticks 180 ticks 181 ticks 182 ticks 183 ticks 184 ticks 185 ticks 186 ticks 187 ticks 188 ticks 189 ticks 190 ticks 191 ticks 192 ticks 193 ticks 194 ticks 195 ticks 196 ticks 197 ticks 198 ticks OnExecution() called!
To reiterate, OnExecution() is not called directly after an EnterLong(). It is called once an order is filled.
Here is a link to our help guide for more information about OnExecution(): http://ninjatrader.com/support/helpG...nexecution.htmZachary G.NinjaTrader Customer Service
-
OK, I wasn't clear on this and it turns out I need to fix my strategy accordingly.
However, I only found it as I let the strategy run in sim mode against a live data feed. This problem has never been seen during Market Replay or using the Backtester after many, many tests. I wonder why the Market Replay simulation engine never exposed this. Can you please explain?
Comment
-
There is really nothing to explain. The Execution event has nothing to do with the BarUpdate event, so how they relate is essentially indeterminate. BarUpdate is an event triggered by a tick, Execution is triggered by an execution, whenever the order is executed, which can be anytime after the order is issued.Originally posted by reynoldsn View PostOK, I wasn't clear on this and it turns out I need to fix my strategy accordingly.
However, I only found it as I let the strategy run in sim mode against a live data feed. This problem has never been seen during Market Replay or using the Backtester after many, many tests. I wonder why the Market Replay simulation engine never exposed this. Can you please explain?
Yes, even market orders do not always execute immediately; at least not before other ticks may have come in. How an order executes is determined by the exchange, not NT.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
574 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
333 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
553 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment