Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Last bar
Collapse
X
-
Hello,
To locate the Last bar, you could use ChartBars.ToIndex.
This would be one example of a way to calculate this:
The mode variable in this example accounts for changing the Calculate mode, this is not necessary if you will be using OnEachTick, for OnBarClose you would need to adjust the count minus 1.Code:int mode = Calculate == Calculate.OnBarClose ? 1 : 0; Print(CurrentBar + " " +(ChartBars.ToIndex - mode));
For a real world use of ChartBars.ToIndex, please see the Misc region in the Pivots indicator.
I look forward to being of further assistance.
-
Hello,
This should handle both tick or price change, the Count would change depending on if you have Intra bar granularity or not.
Using a Print without subtracting the value like shown in the previous example would better highlight the index differences when you toggle the setting.
I look forward to being of further assistance.Code:Print(CurrentBar + " " +ChartBars.ToIndex);
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
557 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