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!
See more
See less

Partner 728x90

Collapse

BoolSeries

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

    BoolSeries

    Hey guys,

    What am I doing wrong here?

    Code:
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    #endregion
    
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        [Description("Enter the description of your new custom indicator here")]
        public class Black : Indicator
        {
            #region Variables
    		//Narrow Range
    		private BoolSeries NR4;
    		private double R1 = 0;
    		private double R2 = 0;
    		private double R3 = 0;
    		private double R4 = 0;
            
            #endregion
    
           
            protected override void Initialize()
            {
                Overlay	= false;
    			NR4 = new BoolSeries(this, MaximumBarsLookBack.Infinite);
            }
    
            
            protected override void OnBarUpdate()
            {
    				
    			if(Bars.GetDayBar(4).Close != null)
    			{
    			R1 = Bars.GetDayBar(1).High - Bars.GetDayBar(1).Low;
    			R2 = Bars.GetDayBar(2).High - Bars.GetDayBar(2).Low;
    			R3 = Bars.GetDayBar(3).High - Bars.GetDayBar(3).Low;
    			R4 = Bars.GetDayBar(4).High - Bars.GetDayBar(4).Low;
    			}
    			else return;
    			
    			NR4.Set(R1 < R2 && R1 < R3 && R1 < R4 ? true : false);
            }
    
            #region Properties
    
            #endregion
        }
    }
    I am getting a error:

    Error on calling 'OnBarUpdate' method for indicator 'Black' on bar 0: Object reference not set to an instance of an object.

    Any help would be appreciated.

    #2
    Hi SodyTexas,

    On the check you're making here:
    if(Bars.GetDayBar(4).Close != null)

    You would want instead:
    if(Bars.GetDayBar(4) != null)
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Awesome, thanks I was stumped on that!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by geddyisodin, 04-25-2024, 05:20 AM
      8 responses
      61 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by jxs_xrj, 01-12-2020, 09:49 AM
      4 responses
      3,288 views
      1 like
      Last Post jgualdronc  
      Started by Option Whisperer, Today, 09:55 AM
      0 responses
      5 views
      0 likes
      Last Post Option Whisperer  
      Started by halgo_boulder, 04-20-2024, 08:44 AM
      2 responses
      22 views
      0 likes
      Last Post halgo_boulder  
      Started by mishhh, 05-25-2010, 08:54 AM
      19 responses
      6,189 views
      0 likes
      Last Post rene69851  
      Working...
      X