My question is how do I identify when I'm at the rightmost bar?
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
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.
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 bortz, 11-06-2023, 08:04 AM
|
47 responses
1,602 views
0 likes
|
Last Post
by aligator
Today, 07:22 PM
|
||
Started by jaybedreamin, Today, 05:56 PM
|
0 responses
8 views
0 likes
|
Last Post
by jaybedreamin
Today, 05:56 PM
|
||
Started by DJ888, 04-16-2024, 06:09 PM
|
6 responses
18 views
0 likes
|
Last Post
by DJ888
Today, 05:12 PM
|
||
Started by Jon17, Today, 04:33 PM
|
0 responses
4 views
0 likes
|
Last Post
by Jon17
Today, 04:33 PM
|
||
Started by Javierw.ok, Today, 04:12 PM
|
0 responses
12 views
0 likes
|
Last Post
by Javierw.ok
Today, 04:12 PM
|
Comment