protected override void OnBarUpdate()
{
Print("0");
if (CurrentBar < BarsRequiredToTrade)
Print("Bars Required to trade not met");
return;
Print("1");
if (State == State.Historical)
Print("State is historical");
return;
Print("2");
// More code below....
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Is OnBarUpdate not executing additional code?
Collapse
X
-
Is OnBarUpdate not executing additional code?
I'm trying to run the strategy with live data with the Sim101 account, but I can't seem to get Print("1") or anything below it to print. I see Print("Bars Required to trade not met") when I first enable the strategy, but all I see is it print zero over and over again without ever seeing it print 1. Is there something else I need to enable for live data? Everything seems to work fine when backtesting and market replay.
Code:Tags: None
-
Disregard this question. I created a new class with a new name and started copying the code over. For some reason it worked for the new class.
-
Glad you have it working ... but for future reference, the following slightly modified code (note the "<<<<" comments) is what will make your original effort work as expected:
Thanks.Code:protected override void OnBarUpdate() { Print("0"); if (CurrentBar < BarsRequiredToTrade) { // <<<<<<<<<<<<<<<< Print("Bars Required to trade not met"); return; } // <<<<<<<<<<<<<<<< Print("1"); if (State == State.Historical) { // <<<<<<<<<<<<<<<< Print("State is historical"); return; } // <<<<<<<<<<<<<<<< Print("2"); // More code below.... }
- Likes 1
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
43 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
21 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
30 views
1 like
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
50 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
40 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment