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

Why parameter section is missing from result

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

    Why parameter section is missing from result

    I cloned from a working indicator program to make changes. It works fine. But the result (see attached) does not have a Parameter section that allows me to change PERIOD. That forces me to change program to have different sets of values tested. What did I do wrong?

    Below is a code segment:

    public class MyWMACrossoverDot : Indicator
    {
    #region Variables
    // Wizard generated variables
    private int fastperiod = 6;
    private int slowperiod = 30;
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    CalculateOnBarClose = false;
    Overlay = true;
    }
    Attached Files

    #2
    Benluk,

    Thank you for your post.

    Is this the full script or just part of it?

    In the full script do you see a Properties region towards the bottom of the script?
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      I add the region Properties. When I compile, I have a warning message:

      Your indicator likely holds one or more recursive properties which could cause Ninja Trader to crash: fastperiod slowperiod.

      // This namespace holds all indicators and is required. Do not change it.
      namespace NinjaTrader.Indicator
      {
      /// <summary>
      ///
      /// </summary>
      [Description("")]
      public class MyWMACrossoverDot : Indicator
      {
      #region Variables
      // Wizard generated variables
      private int fastperiod = 6;
      private int slowperiod = 30;
      // User defined variables (add any user defined variables below)
      #endregion

      /// <summary>
      /// This method is used to configure the indicator and is called once before any bar data is loaded.
      /// </summary>
      protected override void Initialize()
      {
      CalculateOnBarClose = false;
      Overlay = true;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      if (CurrentBar < 2) return;

      if (WMA(Close, fastperiod)[0] > WMA(Close, slowperiod)[0] && WMA(Close, fastperiod)[1] < WMA(Close, slowperiod)[1])
      {DrawArrowUp("tag"+CurrentBar, true, Time[0], Low[0]-(4*TickSize), Color.Cyan);}
      else
      if (WMA(Close, fastperiod)[0] < WMA(Close, slowperiod)[0] && WMA(Close, fastperiod)[1] > WMA(Close, slowperiod)[1])
      {DrawArrowDown("tag"+CurrentBar, true, Time[0], High[0]+(4*TickSize), Color.Red);}
      else
      {RemoveDrawObject("tag"+CurrentBar);}

      }

      #region Properties

      [Description("Number of Period")]
      [GridCategory("Parameters")]
      public int fastperiod
      {
      get { return fastperiod; }
      set { fastperiod = Math.Max(1, value); }
      }

      [Description("Number of Period")]
      [GridCategory("Parameters")]
      public int slowperiod
      {
      get { return slowperiod; }
      set { slowperiod = Math.Max(1, value); }
      }
      #endregion

      }
      }

      Comment


        #4
        Originally posted by Benluk View Post
        I add the region Properties. When I compile, I have a warning message:

        Your indicator likely holds one or more recursive properties which could cause Ninja Trader to crash: fastperiod slowperiod.

        // This namespace holds all indicators and is required. Do not change it.
        namespace NinjaTrader.Indicator
        {
        /// <summary>
        ///
        /// </summary>
        [Description("")]
        public class MyWMACrossoverDot : Indicator
        {
        #region Variables
        // Wizard generated variables
        private int fastperiod = 6;
        private int slowperiod = 30;
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        protected override void Initialize()
        {
        CalculateOnBarClose = false;
        Overlay = true;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
        if (CurrentBar < 2) return;

        if (WMA(Close, fastperiod)[0] > WMA(Close, slowperiod)[0] && WMA(Close, fastperiod)[1] < WMA(Close, slowperiod)[1])
        {DrawArrowUp("tag"+CurrentBar, true, Time[0], Low[0]-(4*TickSize), Color.Cyan);}
        else
        if (WMA(Close, fastperiod)[0] < WMA(Close, slowperiod)[0] && WMA(Close, fastperiod)[1] > WMA(Close, slowperiod)[1])
        {DrawArrowDown("tag"+CurrentBar, true, Time[0], High[0]+(4*TickSize), Color.Red);}
        else
        {RemoveDrawObject("tag"+CurrentBar);}

        }

        #region Properties

        [Description("Number of Period")]
        [GridCategory("Parameters")]
        public int Fastperiod
        {
        get { return fastperiod; }
        set { fastperiod = Math.Max(1, value); }
        }

        [Description("Number of Period")]
        [GridCategory("Parameters")]
        public int Slowperiod
        {
        get { return slowperiod; }
        set { slowperiod = Math.Max(1, value); }
        }
        #endregion

        }
        }
        In each case, your public variable is defined exactly as its backing store. That is a recursive loop that will cause what is in effect an infinite loop of object creation until the computer runs out of memory and crashes.

        There are many ways that resolve the issue. What I have modified in red is the method most often used, and seems to be the Microsoft sanctified method. (That is not the method that I use, as it is not informative enough for my coding style.)
        Last edited by koganam; 05-05-2014, 02:55 PM.

        Comment


          #5
          Although I do not understand, it works. Thank you.

          Could you help me to understand the following coding please? Are the value 1 correctly code for this purpose?

          Within region Properties...

          set { fastperiod = Math.Max(1, value); }
          set { slowperiod = Math.Max(1, value); }

          Comment


            #6
            Originally posted by Benluk View Post
            Although I do not understand, it works. Thank you.

            Could you help me to understand the following coding please? Are the value 1 correctly code for this purpose?

            Within region Properties...

            set { fastperiod = Math.Max(1, value); }
            set { slowperiod = Math.Max(1, value); }
            That just says that the variables' value is the maximum value between 1 and the value supplied through the parameter. In effect, it means that the minimum value that the parameter will supply to the class is 1, as, if a value less than 1 is supplied, then the maximum value between that supplied value and 1 would be 1.
            Last edited by koganam; 04-27-2014, 07:42 AM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Segwin, 05-07-2018, 02:15 PM
            14 responses
            1,789 views
            0 likes
            Last Post aligator  
            Started by Jimmyk, 01-26-2018, 05:19 AM
            6 responses
            838 views
            0 likes
            Last Post emuns
            by emuns
             
            Started by jxs_xrj, 01-12-2020, 09:49 AM
            6 responses
            3,294 views
            1 like
            Last Post jgualdronc  
            Started by Touch-Ups, Today, 10:36 AM
            0 responses
            13 views
            0 likes
            Last Post Touch-Ups  
            Started by geddyisodin, 04-25-2024, 05:20 AM
            11 responses
            63 views
            0 likes
            Last Post halgo_boulder  
            Working...
            X