NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 06-07-2011, 01:32 PM   #1
Lonneman
Junior Member
 
Join Date: Feb 2009
Posts: 21
Thanks: 6
Thanked 0 times in 0 posts
Default Why error in log with NBarsUpEvent in for loop

Hi, I am trying to check if there was an NBarsUp or -Down event during the last 7 bars. I tried this, but it doesn't work and I get an error message in the log: "Error on calling 'OnBarUpdate' method [...] You are accessing an index with a value that is invalid since its out of range.":
Code:
  protected override void OnBarUpdate()
        {
            if (CurrentBar < 45)
                return;            
            
            bool bNBarsUpEvent = false;
            bool bNBarsDownEvent = false;
            
            for (int i = 0; i <= 7; i++)
            {
                double valueUp = NBarsUp(nBarsPeriod, true, true, true)[i]; 
                double valueDown = NBarsDown(nBarsPeriod, true, true, true)[i]; 

                if (valueUp == 1)                
                {
                    bNBarsUpEvent = true;    
                    BackColor = Color.Green;                        
                }                
                
                if (valueDown == 1)                
                {
                    bNBarsDownEvent = true;    
                    BackColor = Color.Red;                        
                }            
            }            
        }
I don't understand why it's not working.
Lonneman is offline  
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Log Mindset Suggestions And Feedback 3 08-17-2010 05:22 AM
NT7B15: Error dialog loop nailz420 Version 7 Beta General Questions & Bug Reports 6 05-07-2010 05:32 AM
Help with Log error huracan Indicator Development 4 10-01-2009 02:41 PM
Help need with error log Trevor.Richter Automated Trading 1 04-11-2009 01:18 AM
Error in Log decklin17 Indicator Development 2 04-10-2009 03:36 PM


All times are GMT -6. The time now is 07:31 PM.