Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Collect Close price and compare

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • NinjaTrader_PaulH
    replied
    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

    Leave a comment:


  • arroganzmaschine
    replied
    Originally posted by NinjaTrader_PatrickH View Post
    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?
    This is the error I get in my output window.


    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:


  • NinjaTrader_PatrickH
    replied
    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:


  • arroganzmaschine
    replied
    Originally posted by NinjaTrader_PatrickH View Post
    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:
    Code:
    for (int i = 10; i > 0; i--)
    {
    DrawHorizontalLine("mytag"+i, 1000, Color.Black);
    }|
    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.htm
    Why does this not work?

    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:


  • NinjaTrader_PatrickH
    replied
    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:
    Code:
    for (int i = 10; i > 0; i--)
    {
    DrawHorizontalLine("mytag"+i, 1000, Color.Black);
    }|
    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.htm

    Leave a comment:


  • arroganzmaschine
    replied
    How can I draw multiple horizontal lines through a loop? The tag somehow interrupts me.

    Leave a comment:


  • arroganzmaschine
    replied
    Ok, I think MaximumBarsLookback.Infinite is the solution. I will keep you updated.

    Leave a comment:


  • arroganzmaschine
    replied
    Originally posted by koganam View Post
    The examples are at the linked pages.
    Yes, that is right. But how do I collect the data already in the chart?

    Leave a comment:


  • koganam
    replied
    Originally posted by arroganzmaschine View Post
    Thank you. Can you give me an example? I first thought DataSeries Class can help me. https://ninjatrader.com/support/help...ries_class.htm
    The examples are at the linked pages.

    Leave a comment:


  • arroganzmaschine
    replied
    Originally posted by koganam View Post
    Thank 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:


  • koganam
    replied
    Originally posted by arroganzmaschine View Post
    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
    Use a Sorted Dictionary, or a Sorted List.

    ref: https://msdn.microsoft.com/en-us/lib...(v=vs.90).aspx
    Represents a collection of key/value pairs that are sorted by the keys and are accessible by key and by index.

    Leave a comment:


  • arroganzmaschine
    replied
    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:


  • arroganzmaschine
    started a topic Collect Close price and compare

    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 sjsj2732  
Started by NullPointStrategies, 03-13-2026, 05:17 AM
0 responses
313 views
0 likes
Last Post NullPointStrategies  
Started by argusthome, 03-08-2026, 10:06 AM
0 responses
319 views
0 likes
Last Post argusthome  
Started by NabilKhattabi, 03-06-2026, 11:18 AM
0 responses
149 views
1 like
Last Post NabilKhattabi  
Started by Deep42, 03-06-2026, 12:28 AM
0 responses
115 views
0 likes
Last Post Deep42
by Deep42
 
Working...
X