• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

regarding null values

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

    regarding null values

    Newbie to Ninjatrader, had some questions regarding null.

    I saw some sample codes where classes are assigned to null.

    Suppose i want to write a code where if the CurrentBar is less than say 10, i want to assign the value null. Is it valid to assign null to values of DataSeries?

    For instance, would this be a correct code:

    if (CurrentBar<Periods) {
    Input[0] = null; // where Input is a DataSeries
    }

    if (Input[0] != null && Input[1] == null) {
    AnotherInput[0] = Input[0]; // where AnotherInput is another DataSeries
    }

    thanks

    #2
    Hello,

    Thank you for your post.

    This would not be possible. When a plot/data series is null, a dummy price is used instead. This will be the Input series which is usually the Close price.

    This is mentioned in the help guide on the Dataseries Class under the heading 'Setting Values - DataSeries.Set() & DataSeries.Reset()'.
    Please see the following link on the data series class: http://www.ninjatrader.com/support/h...ries_class.htm
    Cody B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_CodyB View Post
      Hello,

      Thank you for your post.

      This would not be possible. When a plot/data series is null, a dummy price is used instead. This will be the Input series which is usually the Close price.

      This is mentioned in the help guide on the Dataseries Class under the heading 'Setting Values - DataSeries.Set() & DataSeries.Reset()'.
      Please see the following link on the data series class: http://www.ninjatrader.com/support/h...ries_class.htm
      Cody, thanks for your answer. Another question - to check for Valid Values, the documentation suggests to use DataSeries.ContainsValue(), however if I use Input.ContainsValue(0), when I compile, it shows that Input doesn't contain a ContainsValue method.

      How can I check if the Input contains a valid value or not?

      Also, how can I set DataSeries to invalid value?

      Comment


        #4
        Cody,

        In addition to my question below, I have another question. Suppose I have the following code:

        namespace NinjaTrader.Indicator
        {
        [Description("Learning NinjaScript")]
        public class EMAVG : Indicator
        {
        #region Variables
        // Wizard generated variables
        private double periods = 10.0; // Default setting for Periods
        // User defined variables (add any user defined variables below)
        private DataSeries EMA1;
        private double lambda; // = 2.0/(periods+1.0);
        private double lambda1; // = 1.0-lambda;
        private int periodsint; // = Math.Floor(periods);
        #endregion

        protected override void Initialize()
        {
        Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "EMAVG1"));
        Overlay = true;
        lambda = 2.0/(Periods+1.0);
        lambda1 = 1.0-lambda;
        periodsint = (int) Math.Floor(Periods);
        EMA1 = new DataSeries(this);
        }

        protected override void OnBarUpdate()
        {
        EMA1.Set(CurrentBar == 0 ? Input[0] : Input[0]*lambda + Value[1]*lambda1);
        if (CurrentBar >= periodsint) {
        EMAVG1.Set(EMA1[0]);
        }

        }

        #region Properties
        [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
        [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
        public DataSeries EMAVG1
        {
        get { return Values[0]; }
        }

        [Description("")]
        [GridCategory("Parameters")]
        public double Periods
        {
        get { return periods; }
        set { periods = Math.Max(1, value); }
        }
        #endregion
        }
        }
        In the code above, I set the values for EMAVG1 only after some bars. The code above compiles fine, but the plot is not displayed. The error in the log says:

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

        Why didn't 'OnBarUpdate' method pick up the "dummy price" ?
        Last edited by uday12; 01-25-2016, 06:51 AM.

        Comment


          #5
          Hello,
          The Input, Close, Low High, other NinjaTrader Generated Dataseries will not have ContainsValue as a property. To check if they are a valid value you would need to use IsValidPlot instead. Please see the following link on using DataSeries.IsValidPlot():http://ninjatrader.com/support/helpG...dataseries.htm

          In regards to your second inquiry I have tested the code that was provided on my end and I do not receive any errors when running the indicator. Can you clarify the test environment you are using i.e what type of chart you are running on, what instrument, what days you have set to load?
          This error does not indicate that the "dummy price" was not chosen there could be another error with the logic of the code that would need to be resolved.
          Cody B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Tyler7498, Today, 07:34 PM
          0 responses
          4 views
          0 likes
          Last Post Tyler7498  
          Started by Woomera, Today, 07:24 PM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Started by Newtrader101, Today, 12:31 PM
          2 responses
          13 views
          0 likes
          Last Post Newtrader101  
          Started by kweiss, Today, 06:42 PM
          0 responses
          2 views
          0 likes
          Last Post kweiss
          by kweiss
           
          Started by Newtrader101, Today, 06:31 PM
          0 responses
          6 views
          0 likes
          Last Post Newtrader101  
          Working...
          X