Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Serializing Indicator

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

    Serializing Indicator

    I have a custom indicator which I migrated over from NT 6.5. It compiles properly, without errors, and plots as expected on the chart. However, when I try to save it as a component of a template, I get an error message stating the indicator is unable to be serialized. There is no error code and in the log I get a message which says "Please refer help for more information on serializing indicators". That's it. When I search the help files on serializing indicators or serializing, or serial, I get nothing. So where is the help located that the log file is referencing?
    Thanks
    DaveN
    Last edited by daven; 12-07-2010, 12:31 PM. Reason: Misspellings

    #2
    Hello DaveN,

    The most common property to serialize is user defined color inputs. Details on serializing color inputs are here:


    If you can share the properties region of your code we can tell if it's a different property causing this.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      I inserted most of the indicator program below so you can take a look at it. It is a very simple indicator where I color the region in between and avg of the highs and an average of the lows. I do use some coloring so perhaps that is the issue. Is this serialization element new or enhanced in NT 7.0 because I have had this indicator and used it for years in NT 6.5 and I never had this issue?
      Thanks
      DaveN

      [QUOTE][ #region Variables
      // Wizard generated variables
      private int period = 11; // Default setting for Period
      private int smoother = 3; // Default for 2nd avg Period
      public DataSeries hband;
      public DataSeries lband;
      // 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()
      {
      Add(new Plot(Color.FromKnownColor(KnownColor.Cyan), PlotStyle.Line, "UpperBand"));
      Add(new Plot(Color.FromKnownColor(KnownColor.Maroon), PlotStyle.Line, "LowerBand"));
      hband = new DataSeries(this);
      lband = new DataSeries(this);
      CalculateOnBarClose = true;
      Overlay = true;
      PriceTypeSupported = true;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Use this method for calculating your indicator values. Assign a value to each
      // plot below by replacing 'Close[0]' with your own formula.
      if (CurrentBar < Period)
      return;
      {
      hband.Set(SMA(EMA(High, period), smoother)[0]);
      lband.Set(SMA(EMA(Low, period), smoother)[0]);
      DrawRegion("High-Low Avg Band", CurrentBar, 0, SMA(EMA(High, period), smoother), SMA(EMA(Low, period), smoother), Color.Black, Color.Blue, 2);
      UpperBand.Set(hband[0]);
      LowerBand.Set(lband[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 Plot0
      {
      get { return Values[0]; }
      }

      [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 Plot1
      {
      get { return Values[1]; }
      }

      [Description("")]
      [Category("Parameters")]
      public int Period
      {
      get { return period; }
      set { period = Math.Max(1, value); }
      }
      [Description("")]
      [Category("Parameters")]
      public int Smoother
      {
      get { return smoother; }
      set { smoother = Math.Max(1, value); }
      }

      [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 UpperBand
      {
      get { return Values[0]; }
      }
      [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 LowerBand
      {
      get { return Values[1]; }
      }
      #endregion
      }
      }

      #region NinjaScript generated code. Neither change nor remove.
      // This namespace holds all indicators and is required. Do not change it.
      namespace NinjaTrader.Indicator
      {
      public partial class Indicator : IndicatorBase
      {
      private PT_HighAvg_LowAvg_Band[] cachePT_HighAvg_LowAvg_Band = null;

      private static PT_HighAvg_LowAvg_Band checkPT_HighAvg_LowAvg_Band = new PT_HighAvg_LowAvg_Band();

      /// <summary>
      /// 2 bands created by an average of the highs and of the lows. Plot0 is the HighAvg, Plot1 is the LowAvg
      /// </summary>
      /// <returns></returns>
      public PT_HighAvg_LowAvg_Band PT_HighAvg_LowAvg_Band(int period, int smoother)
      {
      return PT_HighAvg_LowAvg_Band(Input, period, smoother);
      }

      /// <summary>
      /// 2 bands created by an average of the highs and of the lows. Plot0 is the HighAvg, Plot1 is the LowAvg
      /// </summary>
      /// <returns></returns>
      public PT_HighAvg_LowAvg_Band PT_HighAvg_LowAvg_Band(Data.IDataSeries input, int period, int smoother)
      {
      if (cachePT_HighAvg_LowAvg_Band != null)
      for (int idx = 0; idx < cachePT_HighAvg_LowAvg_Band.Length; idx++)
      if (cachePT_HighAvg_LowAvg_Band[idx].Period == period && cachePT_HighAvg_LowAvg_Band[idx].Smoother == smoother && cachePT_HighAvg_LowAvg_Band[idx].EqualsInput(input))
      return cachePT_HighAvg_LowAvg_Band[idx];

      lock (checkPT_HighAvg_LowAvg_Band)
      {
      checkPT_HighAvg_LowAvg_Band.Period = period;
      period = checkPT_HighAvg_LowAvg_Band.Period;
      checkPT_HighAvg_LowAvg_Band.Smoother = smoother;
      smoother = checkPT_HighAvg_LowAvg_Band.Smoother;

      if (cachePT_HighAvg_LowAvg_Band != null)
      for (int idx = 0; idx < cachePT_HighAvg_LowAvg_Band.Length; idx++)
      if (cachePT_HighAvg_LowAvg_Band[idx].Period == period && cachePT_HighAvg_LowAvg_Band[idx].Smoother == smoother && cachePT_HighAvg_LowAvg_Band[idx].EqualsInput(input))
      return cachePT_HighAvg_LowAvg_Band[idx];

      PT_HighAvg_LowAvg_Band indicator = new PT_HighAvg_LowAvg_Band();
      indicator.BarsRequired = BarsRequired;
      indicator.CalculateOnBarClose = CalculateOnBarClose;
      #if NT7
      indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
      indicator.MaximumBarsLookBack = MaximumBarsLookBack;
      #endif
      indicator.Input = input;
      indicator.Period = period;
      indicator.Smoother = smoother;
      Indicators.Add(indicator);
      indicator.SetUp();

      PT_HighAvg_LowAvg_Band[] tmp = new PT_HighAvg_LowAvg_Band[cachePT_HighAvg_LowAvg_Band == null ? 1 : cachePT_HighAvg_LowAvg_Band.Length + 1];
      if (cachePT_HighAvg_LowAvg_Band != null)
      cachePT_HighAvg_LowAvg_Band.CopyTo(tmp, 0);
      tmp[tmp.Length - 1] = indicator;
      cachePT_HighAvg_LowAvg_Band = tmp;
      return indicator;
      }
      }
      }
      }

      // This namespace holds all market analyzer column definitions and is required. Do not change it.
      namespace NinjaTrader.MarketAnalyzer
      {
      public partial class Column : ColumnBase
      {
      /// <summary>
      /// 2 bands created by an average of the highs and of the lows. Plot0 is the HighAvg, Plot1 is the LowAvg
      /// </summary>
      /// <returns></returns>
      [Gui.Design.WizardCondition("Indicator")]
      public Indicator.PT_HighAvg_LowAvg_Band PT_HighAvg_LowAvg_Band(int period, int smoother)
      {
      return _indicator.PT_HighAvg_LowAvg_Band(Input, period, smoother);
      }

      /// <summary>
      /// 2 bands created by an average of the highs and of the lows. Plot0 is the HighAvg, Plot1 is the LowAvg
      /// </summary>
      /// <returns></returns>
      public Indicator.PT_HighAvg_LowAvg_Band PT_HighAvg_LowAvg_Band(Data.IDataSeries input, int period, int smoother)
      {
      return _indicator.PT_HighAvg_LowAvg_Band(input, period, smoother);
      }
      }
      }

      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
      public partial class Strategy : StrategyBase
      {
      /// <summary>
      /// 2 bands created by an average of the highs and of the lows. Plot0 is the HighAvg, Plot1 is the LowAvg
      /// </summary>
      /// <returns></returns>
      [Gui.Design.WizardCondition("Indicator")]
      public Indicator.PT_HighAvg_LowAvg_Band PT_HighAvg_LowAvg_Band(int period, int smoother)
      {
      return _indicator.PT_HighAvg_LowAvg_Band(Input, period, smoother);
      }

      /// <summary>
      /// 2 bands created by an average of the highs and of the lows. Plot0 is the HighAvg, Plot1 is the LowAvg
      /// </summary>
      /// <returns></returns>
      public Indicator.PT_HighAvg_LowAvg_Band PT_HighAvg_LowAvg_Band(Data.IDataSeries input, int period, int smoother)
      {
      if (InInitialize && input == null)
      throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

      return _indicator.PT_HighAvg_LowAvg_Band(input, period, smoother);
      }
      }
      }
      #endregion
      /QUOTE]

      Comment


        #4
        The issue you're seeing is caused by the public DataSeries declaration. These need to be declared private. Changing this should resolve the issue for you.


        #region Variables
        // Wizard generated variables
        private int period = 11; // Default setting for Period
        private int smoother = 3; // Default for 2nd avg Period
        private DataSeries hband;
        private DataSeries lband;
        // User defined variables (add any user defined variables below)
        #endregion

        There hasn't been a change here except that in V7 there are more areas where you can save indicator/chart preferences. These preferences are all saved to an xml file and some properties will need to be serialized so they can be interpreted properly.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Fixed It

          That fixed it Ryan. Thanks so much for your help.
          DaveN

          Comment


            #6
            I have the same problem and your recommendations really solved the problem. But I need that my DataSeries be public and not private because I need to use it in the script of a strategy.
            I mean, I need to write something like MyVariable=MyIndicator.MyDataSeries[bars ago]
            How can I implement something like that if MyDataSeries is private?

            Comment


              #7
              Originally posted by gofortips View Post
              I have the same problem and your recommendations really solved the problem. But I need that my DataSeries be public and not private because I need to use it in the script of a strategy.
              I mean, I need to write something like MyVariable=MyIndicator.MyDataSeries[bars ago]
              How can I implement something like that if MyDataSeries is private?
              Yes. The private DataSeries is merely a backing store. Expose it using public properties, by using the same syntax that is used to expose Plots.

              Comment


                #8
                That's right, the dataseries is exposed by using the same syntax that is used to expose plots. The problem is that the dataseries I want to expose is also ploted.
                In my case, the graph of my dataseries doesn't have any meaning. It wouldn't be important for me if I could plot it in a separated panel and ignore it, but there is no way to tell the script programatically to plot something in a new panel (at least I don't know it's possible)
                My indicator plots several graphs overlayed on the price panel and some others in a second panel with different scales on the right and on the left sides.
                The scale of the dataseries I want to expose is different to both the scales I used on the graphs and graphing this dataseries on the same panel simply makes my graphs to look in an unuseful way.
                Is there any other way (or tip) to solve the problem? I remind you that I tried also defining my dataseries as public and it worked fine, but the problem is that I can't save my graphs as a template because NinjaTrader "complains" about indicator serialization.

                Comment


                  #9
                  Originally posted by gofortips View Post
                  ... I tried also defining my dataseries as public and it worked fine, but the problem is that I can't save my graphs as a template because NinjaTrader "complains" about indicator serialization.
                  Do you have the [XmlIgnore] attribute applied to the public properties of the DataSeries?

                  Comment


                    #10
                    Thanks a lot. I've added the [XmlIgnore] attribute and everything is working the right way.

                    Comment


                      #11
                      Serializtion error upon Template Save

                      I added the [XmlIgnore()] line above all Color Serialization variables
                      and Data Series that I need except Trend which gives me a compile error.

                      Here is what I have:

                      Variables

                      #region Variables
                      private int period = 10; // Default setting for Period
                      private int smoothK = 3; // Default setting for SmoothK
                      private int smoothD = 3; // Default setting for SmoothD
                      private double lessSlope = 3.0; // Min slope required for Up or Dn Color
                      private double flatSlope = 1.5; // Min for Less Slope; Max Slope for Flat

                      private int i; // Iteration counter
                      private DataSeries raw;

                      private Color colorUp = Color.LimeGreen;
                      private Color colorDn = Color.Red;
                      private Color colorUpSlow = Color.Cyan;
                      private Color colorDnSlow = Color.Coral;

                      private Color colorUpHisto = Color.Green;
                      private Color colorDnHisto = Color.Firebrick;
                      private Color colorUpHistoSlow = Color.Cyan;
                      private Color colorDnHistoSlow = Color.Coral;

                      private Color colorFlat = Color.Yellow;
                      private Color colorFlatHisto = Color.Gold;
                      private int plotLineWidth = 3;
                      private int histoLineWidth = 3;

                      private int defaultColorOpacity = 255;

                      public DataSeries Trend; //public
                      #endregion

                      Then i mention Trend like this under Initialize:

                      Trend = new DataSeries(this);


                      My properties section is this:

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

                      [Browsable(false)]
                      [XmlIgnore()]
                      public DataSeries D
                      {
                      get { return Values[1]; }
                      }

                      [Browsable(false)]
                      [XmlIgnore()]
                      public DataSeries Dhisto
                      {
                      get { return Values[2]; }
                      }
                      /*
                      [Browsable(false)]
                      [XmlIgnore()]
                      public DataSeries Trend // Use these values in the GetBMI program or Strategy.
                      {
                      get { return Values[3]; }
                      }
                      */
                      [Description("Size of K (King Size) Lots.")]
                      [Category("Parameters")]
                      [Gui.Design.DisplayName("1 Big Lot Size")]
                      public int Period
                      {
                      get { return period; }
                      set { period = Math.Max(1, value); }
                      }

                      [Description("Fast line smoothing")]
                      [Category("Parameters")]
                      [Gui.Design.DisplayName("2 Big Lot Avg")]
                      public int SmoothK
                      {
                      get { return smoothK; }
                      set { smoothK = Math.Max(1, value); }
                      }

                      [Description("Slow line smoothing")]
                      [Category("Parameters")]
                      [Gui.Design.DisplayName("3 Small Lot Avg")]
                      public int SmoothD
                      {
                      get { return smoothD; }
                      set { smoothD = Math.Max(1, value); }
                      }

                      [Description("Minimum Slope for Up/DN Color. Losing Slope if less than this. Neutral Color if Flat")]
                      [Category("Parameters")]
                      [Gui.Design.DisplayName("4 Less Slope")]
                      public double LessSlope
                      {
                      get { return lessSlope; }
                      set { lessSlope = value; }
                      }

                      [Description("Minimum Slope for Losing Slope Color. Neutral Color if < this = Flat")]
                      [Category("Parameters")]
                      [Gui.Design.DisplayName("5 Flat Slope")]
                      public double FlatSlope
                      {
                      get { return flatSlope; }
                      set { flatSlope = value; }
                      }
                      // ---------- Opacity --------------- //
                      // [XmlIgnore()]
                      [Description("Default color opacity. ")]
                      [Category("Plots")] // from dbUltimate MA
                      [Gui.Design.DisplayName("7 Default Opacity")]
                      public int DefaultColorOpacity
                      {
                      get { return defaultColorOpacity; }
                      set { defaultColorOpacity = Math.Min(255,Math.Max(1,value)); }
                      }

                      // ------- Color UP / Up Slowly--------------- //
                      [XmlIgnore()]
                      [Description("Color of BMI rising more than FlatSlope ")]
                      [Category("Plots")]
                      [Gui.Design.DisplayName("1.10 BMI Rising")]
                      public Color ColorUp
                      {
                      get { return colorUp; }
                      set { colorUp = value; }
                      }

                      [Browsable(false)]
                      public string colorUpSerialize
                      {
                      get { return NinjaTrader.Gui.Design.SerializableColor.ToString( colorUp); }
                      set { colorUp = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
                      }


                      // ------- Color Flat --------------- //
                      [XmlIgnore()]
                      [Description("Color of BMI rising / falling less than MinSlope ")]
                      [Category("Plots")]
                      [Gui.Design.DisplayName("1.13 BMI Flat")]
                      public Color ColorFlat
                      {
                      get { return colorFlat; }
                      set { colorFlat = value; }
                      }

                      [Browsable(false)]
                      public string colorFlatSerialize
                      {
                      get { return NinjaTrader.Gui.Design.SerializableColor.ToString( colorFlat); }
                      set { colorFlat = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
                      }





                      // ------- Color Histogram bars Up / Dn and Flat Slope -------------- //
                      [XmlIgnore()]
                      [Description("Color of Histo UP > LessSlope ")]
                      [Category("Plots")]
                      [Gui.Design.DisplayName("1.16 Histo UP")]
                      public Color ColorUpHisto
                      {
                      get { return colorUpHisto; } //colorUpHistoSlow
                      set { colorUpHisto = value; }
                      }

                      [Browsable(false)]
                      public string colorUpHistoSerialize
                      {
                      get { return NinjaTrader.Gui.Design.SerializableColor.ToString( colorUpHisto); }
                      set { colorUpHisto = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
                      }

                      [XmlIgnore()]
                      [Description("Color of Histo UP > LessSlope ")]
                      [Category("Plots")]
                      [Gui.Design.DisplayName("1.17 Histo UP Slowly")]
                      public Color ColorUpHistoSlow
                      {
                      get { return colorUpHistoSlow; } //colorUpHistoSlow
                      set { colorUpHistoSlow = value; }
                      }

                      [Browsable(false)]
                      public string colorUpHistoSlowSerialize
                      {
                      get { return NinjaTrader.Gui.Design.SerializableColor.ToString( colorUpHistoSlow); }
                      set { colorUpHistoSlow = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
                      }

                      // ------- Color Less Dn Slope : Flat to Falling or Dn Losing Slope --------------- //
                      [XmlIgnore()]
                      [Description("Color of Histo DN < -LessSlope ")]
                      [Category("Plots")]
                      [Gui.Design.DisplayName("1.20 Histo DN")]
                      public Color ColorDnHisto
                      {
                      get { return colorDnHisto; }
                      set { colorDnHisto = value; }
                      }

                      [Browsable(false)]
                      public string colorDnHistoSerialize
                      {
                      get { return NinjaTrader.Gui.Design.SerializableColor.ToString( colorDnHisto); }
                      set { colorDnHisto = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
                      }


                      // ------- Histo Color Flat --------------- //
                      [XmlIgnore()]
                      [Description("Color of Histo Flat : Slope <= flatSlope ")]
                      [Category("Plots")]
                      [Gui.Design.DisplayName("1.18 Histo Flat")]
                      public Color ColorFlatHisto
                      {
                      get { return colorFlatHisto; }
                      set { colorFlatHisto = value; }
                      }

                      [Browsable(false)]
                      public string colorFlatHistoSerialize
                      {
                      get { return NinjaTrader.Gui.Design.SerializableColor.ToString( colorFlatHisto); }
                      set { colorFlatHisto = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
                      }


                      [Description("Width of the BMI Line")]
                      [Category("Plots")]
                      [Gui.Design.DisplayName("1.21 BMI Line Width")]
                      public int PlotLineWidth
                      {
                      get { return plotLineWidth; }
                      set { plotLineWidth = Math.Max(1, value); }
                      }

                      [Description("Width of the BMI Histogram LInes")]
                      [Category("Plots")]
                      [Gui.Design.DisplayName("1.22 BMI Histo Width")]
                      public int HistoLineWidth
                      {
                      get { return histoLineWidth; }
                      set { histoLineWidth = Math.Max(1, value); }
                      }
                      // --------------------------------------------------------

                      #endregion
                      }

                      Notice where I commented out the section on Trend - Values[3]
                      which if I put back in gives me errors.

                      What should I do?

                      Comment


                        #12
                        Originally posted by magnumdbl View Post
                        I added the [XmlIgnore()] line above all Color Serialization variables
                        and Data Series that I need except Trend which gives me a compile error.

                        Here is what I have:

                        Variables

                        #region Variables
                        private int period = 10; // Default setting for Period
                        private int smoothK = 3; // Default setting for SmoothK
                        private int smoothD = 3; // Default setting for SmoothD
                        private double lessSlope = 3.0; // Min slope required for Up or Dn Color
                        private double flatSlope = 1.5; // Min for Less Slope; Max Slope for Flat

                        private int i; // Iteration counter
                        private DataSeries raw;

                        private Color colorUp = Color.LimeGreen;
                        private Color colorDn = Color.Red;
                        private Color colorUpSlow = Color.Cyan;
                        private Color colorDnSlow = Color.Coral;

                        private Color colorUpHisto = Color.Green;
                        private Color colorDnHisto = Color.Firebrick;
                        private Color colorUpHistoSlow = Color.Cyan;
                        private Color colorDnHistoSlow = Color.Coral;

                        private Color colorFlat = Color.Yellow;
                        private Color colorFlatHisto = Color.Gold;
                        private int plotLineWidth = 3;
                        private int histoLineWidth = 3;

                        private int defaultColorOpacity = 255;

                        public DataSeries Trend; //public
                        #endregion

                        Then i mention Trend like this under Initialize:

                        Trend = new DataSeries(this);


                        My properties section is this:

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

                        [Browsable(false)]
                        [XmlIgnore()]
                        public DataSeries D
                        {
                        get { return Values[1]; }
                        }

                        [Browsable(false)]
                        [XmlIgnore()]
                        public DataSeries Dhisto
                        {
                        get { return Values[2]; }
                        }
                        /*
                        [Browsable(false)]
                        [XmlIgnore()]
                        public DataSeries Trend // Use these values in the GetBMI program or Strategy.
                        {
                        get { return Values[3]; }
                        }
                        */
                        [Description("Size of K (King Size) Lots.")]
                        [Category("Parameters")]
                        [Gui.Design.DisplayName("1 Big Lot Size")]
                        public int Period
                        {
                        get { return period; }
                        set { period = Math.Max(1, value); }
                        }

                        [Description("Fast line smoothing")]
                        [Category("Parameters")]
                        [Gui.Design.DisplayName("2 Big Lot Avg")]
                        public int SmoothK
                        {
                        get { return smoothK; }
                        set { smoothK = Math.Max(1, value); }
                        }

                        [Description("Slow line smoothing")]
                        [Category("Parameters")]
                        [Gui.Design.DisplayName("3 Small Lot Avg")]
                        public int SmoothD
                        {
                        get { return smoothD; }
                        set { smoothD = Math.Max(1, value); }
                        }

                        [Description("Minimum Slope for Up/DN Color. Losing Slope if less than this. Neutral Color if Flat")]
                        [Category("Parameters")]
                        [Gui.Design.DisplayName("4 Less Slope")]
                        public double LessSlope
                        {
                        get { return lessSlope; }
                        set { lessSlope = value; }
                        }

                        [Description("Minimum Slope for Losing Slope Color. Neutral Color if < this = Flat")]
                        [Category("Parameters")]
                        [Gui.Design.DisplayName("5 Flat Slope")]
                        public double FlatSlope
                        {
                        get { return flatSlope; }
                        set { flatSlope = value; }
                        }
                        // ---------- Opacity --------------- //
                        // [XmlIgnore()]
                        [Description("Default color opacity. ")]
                        [Category("Plots")] // from dbUltimate MA
                        [Gui.Design.DisplayName("7 Default Opacity")]
                        public int DefaultColorOpacity
                        {
                        get { return defaultColorOpacity; }
                        set { defaultColorOpacity = Math.Min(255,Math.Max(1,value)); }
                        }

                        // ------- Color UP / Up Slowly--------------- //
                        [XmlIgnore()]
                        [Description("Color of BMI rising more than FlatSlope ")]
                        [Category("Plots")]
                        [Gui.Design.DisplayName("1.10 BMI Rising")]
                        public Color ColorUp
                        {
                        get { return colorUp; }
                        set { colorUp = value; }
                        }

                        [Browsable(false)]
                        public string colorUpSerialize
                        {
                        get { return NinjaTrader.Gui.Design.SerializableColor.ToString( colorUp); }
                        set { colorUp = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
                        }


                        // ------- Color Flat --------------- //
                        [XmlIgnore()]
                        [Description("Color of BMI rising / falling less than MinSlope ")]
                        [Category("Plots")]
                        [Gui.Design.DisplayName("1.13 BMI Flat")]
                        public Color ColorFlat
                        {
                        get { return colorFlat; }
                        set { colorFlat = value; }
                        }

                        [Browsable(false)]
                        public string colorFlatSerialize
                        {
                        get { return NinjaTrader.Gui.Design.SerializableColor.ToString( colorFlat); }
                        set { colorFlat = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
                        }





                        // ------- Color Histogram bars Up / Dn and Flat Slope -------------- //
                        [XmlIgnore()]
                        [Description("Color of Histo UP > LessSlope ")]
                        [Category("Plots")]
                        [Gui.Design.DisplayName("1.16 Histo UP")]
                        public Color ColorUpHisto
                        {
                        get { return colorUpHisto; } //colorUpHistoSlow
                        set { colorUpHisto = value; }
                        }

                        [Browsable(false)]
                        public string colorUpHistoSerialize
                        {
                        get { return NinjaTrader.Gui.Design.SerializableColor.ToString( colorUpHisto); }
                        set { colorUpHisto = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
                        }

                        [XmlIgnore()]
                        [Description("Color of Histo UP > LessSlope ")]
                        [Category("Plots")]
                        [Gui.Design.DisplayName("1.17 Histo UP Slowly")]
                        public Color ColorUpHistoSlow
                        {
                        get { return colorUpHistoSlow; } //colorUpHistoSlow
                        set { colorUpHistoSlow = value; }
                        }

                        [Browsable(false)]
                        public string colorUpHistoSlowSerialize
                        {
                        get { return NinjaTrader.Gui.Design.SerializableColor.ToString( colorUpHistoSlow); }
                        set { colorUpHistoSlow = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
                        }

                        // ------- Color Less Dn Slope : Flat to Falling or Dn Losing Slope --------------- //
                        [XmlIgnore()]
                        [Description("Color of Histo DN < -LessSlope ")]
                        [Category("Plots")]
                        [Gui.Design.DisplayName("1.20 Histo DN")]
                        public Color ColorDnHisto
                        {
                        get { return colorDnHisto; }
                        set { colorDnHisto = value; }
                        }

                        [Browsable(false)]
                        public string colorDnHistoSerialize
                        {
                        get { return NinjaTrader.Gui.Design.SerializableColor.ToString( colorDnHisto); }
                        set { colorDnHisto = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
                        }


                        // ------- Histo Color Flat --------------- //
                        [XmlIgnore()]
                        [Description("Color of Histo Flat : Slope <= flatSlope ")]
                        [Category("Plots")]
                        [Gui.Design.DisplayName("1.18 Histo Flat")]
                        public Color ColorFlatHisto
                        {
                        get { return colorFlatHisto; }
                        set { colorFlatHisto = value; }
                        }

                        [Browsable(false)]
                        public string colorFlatHistoSerialize
                        {
                        get { return NinjaTrader.Gui.Design.SerializableColor.ToString( colorFlatHisto); }
                        set { colorFlatHisto = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
                        }


                        [Description("Width of the BMI Line")]
                        [Category("Plots")]
                        [Gui.Design.DisplayName("1.21 BMI Line Width")]
                        public int PlotLineWidth
                        {
                        get { return plotLineWidth; }
                        set { plotLineWidth = Math.Max(1, value); }
                        }

                        [Description("Width of the BMI Histogram LInes")]
                        [Category("Plots")]
                        [Gui.Design.DisplayName("1.22 BMI Histo Width")]
                        public int HistoLineWidth
                        {
                        get { return histoLineWidth; }
                        set { histoLineWidth = Math.Max(1, value); }
                        }
                        // --------------------------------------------------------

                        #endregion
                        }

                        Notice where I commented out the section on Trend - Values[3]
                        which if I put back in gives me errors.

                        What should I do?
                        In the variables section, you should declare your DataSeries as private. The properties are what are used to expose the values for access from outside the class. Inside the class, the private object should be treated as a backing store for the public declaration. That is an obvious mistake, but without the text of your errors, it is hard to say if that is the only issue. What is the text of your errors, and where and when are you seeing the errors?

                        Comment


                          #13
                          Serialization error when Templating

                          Thanks Koganam , that was a good tip but my code didn't quite work.

                          So I made a couple more changes:

                          I made this change in Variables section:

                          private DataSeries trend; (as you suggested)

                          and this change in Properties:

                          [Browsable(false)]
                          [XmlIgnore()]
                          public DataSeries Trend
                          {
                          get { return trend; } //<= this used to be get { return Values[3]; }
                          }

                          I also changed in Initialize section

                          trend = new DataSeries(this); // I did have this a Trend = ..................

                          This eliminated the compile error is CS0102 = definintion already exists,
                          thus solving my problem.

                          Don

                          Comment


                            #14
                            Another Serialization Problem

                            I think the colors are serialized properly, but there is also a Method Serialization
                            which may cause this not to save in Templates.

                            enums:
                            public enum SineWaveMethodEnum
                            {
                            CyberneticsAnalysis,
                            RocketScience
                            }

                            public enum SmoothMethodEnum
                            {
                            SMA,
                            WMA,
                            HMA,
                            JMA,
                            VWMA
                            }

                            Variables:
                            private Color supportColor = Color.Lime;
                            private Color resistanceColor = Color.Blue;
                            private int defaultColorOpacity = 255;
                            private int widthSRlines = 3;
                            private Color currDotColor;
                            private double currDotValue;
                            private string dotText = "l";
                            private Font pfont = new Font("Wingdings", 4, FontStyle.Bold, GraphicsUnit.Point);
                            private int yPixels = 0;
                            private bool drawingSupport = true;

                            // Variables transsferable to Strategy programs.
                            private DataSeries supportSW; // Price of support dots.
                            private DataSeries resistanceSW; // Price of resistance dots.
                            private DataSeries trendSW;

                            Initialize
                            // ----- DataSeries for export to Strategies ----- //
                            trendSW = new DataSeries(this);
                            supportSW = new DataSeries(this);
                            resistanceSW = new DataSeries(this);

                            Properties
                            [XmlIgnore()]
                            [Browsable(false)]
                            public DataSeries SupportSW
                            {
                            get { return supportSW; }
                            }

                            [XmlIgnore()]
                            [Browsable(false)]
                            public DataSeries ResistanceSW
                            {
                            get { return resistanceSW; }
                            }

                            [XmlIgnore()]
                            [Browsable(false)]
                            public DataSeries TrendSW
                            {
                            get { return trendSW; }
                            }

                            [XmlIgnore()]
                            [Description("Determines what method to use when calculating the sine. Two different ways were presented by Ehlers in two different books, the names of the methods are according to the book name.")]
                            [Category("Parameters")]
                            [Gui.Design.DisplayNameAttribute("Sine Method")]
                            public NinjaTrader.Indicator.dbSineWave.SineWaveMethodEnu m Method
                            {
                            get {return method;}
                            set {method = value;}
                            }
                            [Browsable(false)]
                            public string MethodSerialize
                            {
                            get { return method.ToString(); }
                            set { method = (SineWaveMethodEnum)Enum.Parse(typeof(SineWaveMeth odEnum), value, true); }
                            }

                            [XmlIgnore()]
                            [Description("Determines the method for smoothing the price.")]
                            [Category("Rocket Science")]
                            [Gui.Design.DisplayNameAttribute("Smooth Method")]
                            public NinjaTrader.Indicator.dbSineWave.SmoothMethodEnum SmoothMethod
                            {
                            get {return smoothMethod;}
                            set {smoothMethod = value;}
                            }
                            [Browsable(false)]
                            public string SmoothMethodSerialize
                            {
                            get { return smoothMethod.ToString(); }
                            set { smoothMethod = (SmoothMethodEnum)Enum.Parse(typeof(SmoothMethodEn um), value, true); }
                            }

                            [XmlIgnore()]
                            [Description("Resistance dots color. Make Transparent if creating Lines with Get program.")]
                            [Category("Appearance")]
                            [Gui.Design.DisplayNameAttribute("1 - Resistance Color")]
                            public Color ResistanceColor
                            {
                            get {return resistanceColor;}
                            set {resistanceColor = value;}
                            }
                            [Browsable(false)]
                            public string ResistanceColorSerialize
                            {
                            get { return NinjaTrader.Gui.Design.SerializableColor.ToString( resistanceColor); }
                            set { resistanceColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
                            }

                            [XmlIgnore()]
                            [Description("Support dots color. Make Transparent if creating Lines with Get program.")]
                            [Category("Appearance")]
                            [Gui.Design.DisplayNameAttribute("2 - Support Color")]
                            public Color SupportColor
                            {
                            get {return supportColor;}
                            set {supportColor = value;}
                            }
                            [Browsable(false)]
                            public string SupportColorSerialize
                            {
                            get { return NinjaTrader.Gui.Design.SerializableColor.ToString( supportColor); }
                            set { supportColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
                            }

                            Do you think it is the Method Serializations that are causing the problem?

                            Comment


                              #15
                              Enums are already strings, albeit being mapped to int's in their implementation. So there is no need to write a method to serialize enums.
                              Last edited by koganam; 04-07-2012, 06:25 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              636 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              366 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              107 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              568 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              571 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X