My question is how do I identify when I'm at the rightmost bar?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Identifying the rightmost bar
Collapse
X
-
Identifying the rightmost bar
I'm trying to do a historical study. I am count the total number of bars and the number of bars where the previous bar's close equals the current bar's open. When I get to the rightmost bar, I want to print the counts to the output window.
My question is how do I identify when I'm at the rightmost bar?Tags: None
-
Hi Rcheezem,
Thank you for posting.
If you want the bar being currently built you will need to change the CalculateOnBarClose to false for that to be the CurrentBar or Bar index [0]. Otherwise if COBC is set to true then the second bar to the right becomes the CurrentBar or Bar index[0].
Please take a look at the link below on the CalculateOnBarClose.
http://www.ninjatrader.com/support/h...onbarclose.htm
Let me know if I can be of further assistance.Cal H.NinjaTrader Customer Service
-
Cal, thank you for your help. But I still don't understand. When I set CalculateOnBarClose to false, I keep getting updates on each tick (I think). Could you show me a simple code sample.
Cal here is my code. I hope it will help show you what I'm trying to do.
protectedoverridevoid OnBarUpdate()
{
if (CurrentBar < 2)
{
totalBarsCounted++;
return;
}
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
totalBarsCounted++;
if (Close[1] != Open[0]) totalGapCount++ ;
// I would like to print this line once per chart.
Print("Bars Counted so far are: " + totalBarsCounted +
" Gap Count is " + totalGapCount +
" Percent of Gaps: " + (double)totalGapCount / totalBarsCounted );
}
Comment
-
What I'm trying to do is count the number of daily bars that have a GAP. I want to print the counts (totalBarCount and totalGapCount) when the indicator gets to the last bar on the chart. I don't know how to recognize the last bar on the chart. In fact the last bar may not be complete (Closed).
Comment
-
Rcheezem,
There are a couple things to understand here -
Firstly, the chart bars will work from right to left. Meaning CurrentBar or Bar[0] will be the right most closed bar on the chart. When the bar being built by the data feed gets closed it will become Bar[0] and the previous Bar[0] will become Bar[1].
When CalculateOnBarClose is set to false, OnBarUpdate() will get called with each incoming tick. Additionally, the bar being built by the data feed becomes Bar[0] and the bar to the left of it becomes Bar[1].
You can use 'Count' to print out how many bars are currently on the chart.
Here is a link for the Count function -Code:Print(Count);
http://www.ninjatrader.com/support/h...html?count.htm
Let me know if I can help furtherCal H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
656 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
371 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 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
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
579 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment