Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Straightforward IsLastBar
Collapse
X
-
Straightforward IsLastBar
There should be a straightforward IsLastBar property on Bars. Yes, you can do something like CurrentBar == Bars.Count - 2 (or -1, depending on Calculate and State) but explaining this endless times or trying to figure out exactly which case applies is cumbersome (only to have someone change the Calculate mode and if you didn't handle all the cases this time because you thought it was a certain way... well, now it doesn't work). There should have been, and still should be, a simple Boolean for whether this is the last bar for use in OnBarUpdate. This improvement is easy to deliver, and would make NinjaTrader programming more accessible to new users.Tags: None
-
Hello QuantKey_Bruce,
This is left out because there are very limited cases where using that would be valid. That generally goes against how NinjaScript files process.
You wouldn't normally use a condition like that when making a NinjaScript file. A new user who is making a normal script, for example an average, would not be using that. In almost all cases you should not be using that type of a condition and instead processing each bar in order to provide continuous calculations. That is important for any indicator that is a signal.
In very specific use cases you may need to wait until the last bar of processing, for example as a convenience in debugging, but we generally suggest to avoid doing that and instead process each bar as it comes in to provide a continuous result.
I will make a note about this for development to view but otherwise you already have the correct solution to just subtract the Count from CurrentBar if you need to specifically do that wait till the last bar of historical. Alternatively you can wait until realtime and use 1 BarsAgo to get the last bar of historical if you needed values from that bar.
If you find that you are explaining this frequently you are likely dealing with specific cases that may require that type of logic which would be more advanced. Both CurrentBar and Count are documented so it would be up to the user if they wanted to use those values to do math to find the last bar. This also would not be a valid condition when using TickReplay so there is not a 1 stop solution to finding the LastBar, Count increments when using TickReplay so other logic would be needed that involves OnStatChange to make that type of condition.
JesseNinjaTrader Customer Service
-
It is exactly my point that there should be a one-stop solution. NinjaTrader could define it carefullly so that new users would not be confused. An example of when they might want to use IsLastBar would be if they are playing a sound for a condition or displaying some visual but only in realtime, or if they want to output a text file with some data in it but only when they reach the last bar. They can't necessarily use State == State.Realtime in OnBarUpdate because they could be starting up on a weekend and wouldn't get the file output.
The fact that your explanation has to have a lot of cases in it is precisely why it should be built-in - so they shouldn't have to think about this.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by fx.practic, 10-15-2013, 12:53 AM
|
5 responses
5,403 views
0 likes
|
Last Post
by Bidder
Today, 12:22 AM
|
||
Started by Shai Samuel, 07-02-2022, 02:46 PM
|
4 responses
94 views
0 likes
|
Last Post
by Bidder
Today, 12:11 AM
|
||
Started by DJ888, Yesterday, 10:57 PM
|
0 responses
6 views
0 likes
|
Last Post
by DJ888
Yesterday, 10:57 PM
|
||
Started by MacDad, 02-25-2024, 11:48 PM
|
7 responses
158 views
0 likes
|
Last Post Yesterday, 10:23 PM | ||
Started by Belfortbucks, Yesterday, 09:29 PM
|
0 responses
8 views
0 likes
|
Last Post
by Belfortbucks
Yesterday, 09:29 PM
|
Comment