Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Collect Close price and compare
Collapse
X
-
Hello arroganzmaschine,
Thanks for your reply.
The error message is advising you that you are accessing something that does not exist. What is happening is that when the bars are loading into your indicator, you code begins executing on the first bar, bar 0, then loads bar 1, then 2, etc.etc. Your code on the first bar does this:
for(int i=10; i>0;i--)
{
DrawHorizontalLine("tag"+i, Close[i], Color.Blue);
}
On bar zero would be trying to access Close[10] which is 10 bars ago and there are no bars before zero.
To prevent the issue you would delay processing until you have the minimum bars needed. You can use the CurrentBar as this holds the index of the current bar being processed. In the example you would return (not process) until you had 10 bars.
if (CurrentBar < 10) return; // return until bar 10
for(int i=10; i>0;i--)
{
DrawHorizontalLine("tag"+i, Close[i], Color.Blue);
}
Please see: http://ninjatrader.com/support/helpG...currentbar.htm
-
This is the error I get in my output window.Originally posted by NinjaTrader_PatrickH View PostHello arroganzmaschine,
Thank you for your response.
Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?
Error on calling 'OnBarUpdate' method for indicator 'MountGlen' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
Leave a comment:
-
Hello arroganzmaschine,
Thank you for your response.
Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?
Leave a comment:
-
Why does this not work?Originally posted by NinjaTrader_PatrickH View PostHello arroganzmaschine,
Thank you for your posts.
For the loop and usign drawing obects you can add the variable used in the loop to the tag. For example:
For the closes, why not just call Close which is already a DataSeries containing the close prices? Close: http://ninjatrader.com/support/helpGuides/nt7/close.htmCode:for (int i = 10; i > 0; i--) { DrawHorizontalLine("mytag"+i, 1000, Color.Black); }|
Code:protected override void OnBarUpdate() { for(int i=10; i>0;i--) { DrawHorizontalLine("tag"+i, Close[i], Color.Blue); } }Last edited by arroganzmaschine; 06-13-2016, 12:47 PM.
Leave a comment:
-
Hello arroganzmaschine,
Thank you for your posts.
For the loop and usign drawing obects you can add the variable used in the loop to the tag. For example:
For the closes, why not just call Close which is already a DataSeries containing the close prices? Close: http://ninjatrader.com/support/helpGuides/nt7/close.htmCode:for (int i = 10; i > 0; i--) { DrawHorizontalLine("mytag"+i, 1000, Color.Black); }|
Leave a comment:
-
How can I draw multiple horizontal lines through a loop? The tag somehow interrupts me.
Leave a comment:
-
Ok, I think MaximumBarsLookback.Infinite is the solution. I will keep you updated.
Leave a comment:
-
Yes, that is right. But how do I collect the data already in the chart?Originally posted by koganam View PostThe examples are at the linked pages.
Leave a comment:
-
The examples are at the linked pages.Originally posted by arroganzmaschine View PostThank you. Can you give me an example? I first thought DataSeries Class can help me. https://ninjatrader.com/support/help...ries_class.htm
Leave a comment:
-
Thank you. Can you give me an example? I first thought DataSeries Class can help me. https://ninjatrader.com/support/help...ries_class.htmOriginally posted by koganam View PostUse a Sorted Dictionary, or a Sorted List.
ref: https://msdn.microsoft.com/en-us/lib...(v=vs.90).aspx
https://msdn.microsoft.com/en-us/lib...(v=vs.90).aspx
Leave a comment:
-
Use a Sorted Dictionary, or a Sorted List.Originally posted by arroganzmaschine View PostHello NT-Community,
I've started over with NinjaScript programming and have a few questions about an indicator I'm currently on.
I want to store the close price of every bar of the whole chart and compare them. To compare them, I want to view a timespan of 60 minutes and compare these 60 close prices. If there are 5 close prices who are the same, I want to put out an alert.
My ideas on that:
I know how to compare and how to put an alert. But I don't know how I can store data and compare them in different timespans. Can you help me there? Would be glad.
Thank you very much in advance.
Max
ref: https://msdn.microsoft.com/en-us/lib...(v=vs.90).aspx
Leave a comment:
-
Ok, to compare the close price from minute 1 to minute 60, and then minute 2 to minute 61 I have an idea. But how do I store all the close prices from my chart in an array?
Leave a comment:
-
Collect Close price and compare
Hello NT-Community,
I've started over with NinjaScript programming and have a few questions about an indicator I'm currently on.
I want to store the close price of every bar of the whole chart and compare them. To compare them, I want to view a timespan of 60 minutes and compare these 60 close prices. If there are 5 close prices who are the same, I want to put out an alert.
My ideas on that:
I know how to compare and how to put an alert. But I don't know how I can store data and compare them in different timespans. Can you help me there? Would be glad.
Thank you very much in advance.
Max
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by sjsj2732, 03-23-2026, 04:31 AM
|
0 responses
78 views
0 likes
|
Last Post
by sjsj2732
03-23-2026, 04:31 AM
|
||
|
Started by NullPointStrategies, 03-13-2026, 05:17 AM
|
0 responses
313 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
319 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
149 views
1 like
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
115 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|

Leave a comment: