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

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 Barry Milan, Yesterday, 10:35 PM
          5 responses
          16 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by DanielSanMartin, Yesterday, 02:37 PM
          2 responses
          13 views
          0 likes
          Last Post DanielSanMartin  
          Started by DJ888, 04-16-2024, 06:09 PM
          4 responses
          12 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by terofs, Today, 04:18 PM
          0 responses
          11 views
          0 likes
          Last Post terofs
          by terofs
           
          Started by nandhumca, Today, 03:41 PM
          0 responses
          8 views
          0 likes
          Last Post nandhumca  
          Working...
          X