Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Twice through OnBarUpdate()?
Collapse
X
-
Twice through OnBarUpdate()?
Is there a way to have OnBarUpate() be called twice? My strategy really needs two iterations to be effective. Thanks in advance for the answer. -Dean
Tags: None
-
Not being an under the Ninja hood guru all I can say is, I doubt it.
However...
there are plenty of ways to run your code twice within a single call to OnBarUpdate().
for(int i = 0; i < 2; i++)
{
your code here
}
You gain an advantage of knowing what pass you are ont hrough your code by checking the value of i being 0 for the first pass or 1 for the second. Or if you want to make it simplier on the noggin you can set i = 1 and i < 3 for parameters and check i = 1 or i=2 for whcih pass.
You could also put your code in a function and just call that twice.
or a few other ways.
So, I doubt you'll get two unique calls to OnBarUpdate() but that doesn't mean you can't run your code twice.
-
Sure I could do that, but that won't work in my case. I need the 2nd time through to know how many total bars there are, or iow what the rightmost (most recent) bar number is on the 2nd time through. I asked this question last weekend in a different way, but I'm still searching for a better answer.Originally posted by Newshues View PostNot being an under the Ninja hood guru all I can say is, I doubt it.
However...
there are plenty of ways to run your code twice within a single call to OnBarUpdate().
for(int i = 0; i < 2; i++)
{
your code here
}
Comment
-
try
{
junk = SMA(counter);
counter++;
}
catch
{
TotalBars = counter - 1;
}
that's not the exact way to do it but there is an example of try-catch blocks over in the reference section.
You'd also have to include some kind of check to ensure the current bars time is equal to the current time before processing anything.
and I doubt it will ever be exact.
Comment
-
I am not sure what are you trying to achieve, but it does not really matter how many times you run your code snipet in OnBarUpdate, since it will return the same bar number everytime.Originally posted by cybertunerone View PostSure I could do that, but that won't work in my case. I need the 2nd time through to know how many total bars there are, or iow what the rightmost (most recent) bar number is on the 2nd time through. I asked this question last weekend in a different way, but I'm still searching for a better answer.
If you really need the last (current in the realtime) bar number,I suggest using:
if(!Historical) Print(CurrentBar.ToString()); //or do your other stuff
You can set CalculateOnBarClose to false to get the last "live" bar numberLast edited by roonius; 02-08-2009, 02:54 AM.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
558 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
324 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
545 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
547 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment