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
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. -DeanTags: 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.
-
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
-
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 ETFVoyageur, Today, 04:00 PM
|
0 responses
5 views
0 likes
|
Last Post
by ETFVoyageur
Today, 04:00 PM
|
||
Started by AaronKTradingForum, Today, 03:44 PM
|
1 response
6 views
0 likes
|
Last Post Today, 03:51 PM | ||
Started by Felix Reichert, 04-26-2024, 02:12 PM
|
11 responses
77 views
0 likes
|
Last Post Today, 03:18 PM | ||
Started by junkone, 04-28-2024, 02:19 PM
|
7 responses
82 views
1 like
|
Last Post
by junkone
Today, 03:15 PM
|
||
Started by pechtri, 06-22-2023, 02:31 AM
|
11 responses
136 views
0 likes
|
Last Post
by Nyman
Today, 02:59 PM
|
Comment