Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator Serialization

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

    Indicator Serialization

    Hello Ninjatrader,

    I am having a heak of a time trying to fix a serialization issue:



    One thing worth mentioning that the code does not plot anything but does draw text on each Point and Figure bar. I know most common serialization issues comes from color but am stumped on how to fix it.

    I have researched this: http://www.ninjatrader.com/support/f...ead.php?t=4977

    Here is the code causing me issues..

    Code:

    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 PnFCount : Indicator
        {
            #region Variables
            private int BoxSize = 7;
    		public DataSeries count;
            #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()
            {
                Overlay				= true;
    			count = new DataSeries(this);
    			CalculateOnBarClose = false;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                if(CurrentBar <= 4)return;
    			count[0] = Math.Round((((High[0] - Low[0])/TickSize)/BoxSize)+1,0);
    			if (FirstTickOfBar)
    			{
    				Print("High: "+High[1]+" Low: "+Low[1]);
    			}
    			if(Open[0] < Close[0])
    			{
    				DrawText("count"+CurrentBar.ToString(),count[0].ToString(),0,Close[0]+(BoxSize*TickSize),Color.DimGray);
    			}
    			else
    			{
    				DrawText("count"+CurrentBar.ToString(),count[0].ToString(),0,Close[0]-(BoxSize*TickSize),Color.DimGray);
    			}
            }
    
            #region Properties
    		[Description("Numbers of bars used for calculations")]
    		[GridCategory("Parameters")]
    		public int Box_Size
    		{
    			get { return BoxSize; }
    			set { BoxSize = Math.Max(1, value); }
    		}
            #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 PnFCount[] cachePnFCount = null;
    
            private static PnFCount checkPnFCount = new PnFCount();
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public PnFCount PnFCount(int box_Size)
            {
                return PnFCount(Input, box_Size);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public PnFCount PnFCount(Data.IDataSeries input, int box_Size)
            {
                if (cachePnFCount != null)
                    for (int idx = 0; idx < cachePnFCount.Length; idx++)
                        if (cachePnFCount[idx].Box_Size == box_Size && cachePnFCount[idx].EqualsInput(input))
                            return cachePnFCount[idx];
    
                lock (checkPnFCount)
                {
                    checkPnFCount.Box_Size = box_Size;
                    box_Size = checkPnFCount.Box_Size;
    
                    if (cachePnFCount != null)
                        for (int idx = 0; idx < cachePnFCount.Length; idx++)
                            if (cachePnFCount[idx].Box_Size == box_Size && cachePnFCount[idx].EqualsInput(input))
                                return cachePnFCount[idx];
    
                    PnFCount indicator = new PnFCount();
                    indicator.BarsRequired = BarsRequired;
                    indicator.CalculateOnBarClose = CalculateOnBarClose;
    #if NT7
                    indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                    indicator.MaximumBarsLookBack = MaximumBarsLookBack;
    #endif
                    indicator.Input = input;
                    indicator.Box_Size = box_Size;
                    Indicators.Add(indicator);
                    indicator.SetUp();
    
                    PnFCount[] tmp = new PnFCount[cachePnFCount == null ? 1 : cachePnFCount.Length + 1];
                    if (cachePnFCount != null)
                        cachePnFCount.CopyTo(tmp, 0);
                    tmp[tmp.Length - 1] = indicator;
                    cachePnFCount = 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>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.PnFCount PnFCount(int box_Size)
            {
                return _indicator.PnFCount(Input, box_Size);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public Indicator.PnFCount PnFCount(Data.IDataSeries input, int box_Size)
            {
                return _indicator.PnFCount(input, box_Size);
            }
        }
    }
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        public partial class Strategy : StrategyBase
        {
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.PnFCount PnFCount(int box_Size)
            {
                return _indicator.PnFCount(Input, box_Size);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public Indicator.PnFCount PnFCount(Data.IDataSeries input, int box_Size)
            {
                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.PnFCount(input, box_Size);
            }
        }
    }
    #endregion

    #2
    Hello SodyTexas,

    Thank you for your post.

    We are not able to see the URL image attachment that you have sent us.

    What is the exact error message you are receiving?
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by SodyTexas View Post
      Hello Ninjatrader,

      I am having a heak of a time trying to fix a serialization issue:



      One thing worth mentioning that the code does not plot anything but does draw text on each Point and Figure bar. I know most common serialization issues comes from color but am stumped on how to fix it.

      I have researched this: http://www.ninjatrader.com/support/f...ead.php?t=4977

      Here is the code causing me issues..

      Code:

      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 PnFCount : Indicator
          {
              #region Variables
              private int BoxSize = 7;
      		public DataSeries count;
              #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()
              {
                  Overlay				= true;
      			count = new DataSeries(this);
      			CalculateOnBarClose = false;
              }
      
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
                  if(CurrentBar <= 4)return;
      			count[0] = Math.Round((((High[0] - Low[0])/TickSize)/BoxSize)+1,0);
      			if (FirstTickOfBar)
      			{
      				Print("High: "+High[1]+" Low: "+Low[1]);
      			}
      			if(Open[0] < Close[0])
      			{
      				DrawText("count"+CurrentBar.ToString(),count[0].ToString(),0,Close[0]+(BoxSize*TickSize),Color.DimGray);
      			}
      			else
      			{
      				DrawText("count"+CurrentBar.ToString(),count[0].ToString(),0,Close[0]-(BoxSize*TickSize),Color.DimGray);
      			}
              }
      
              #region Properties
      		[Description("Numbers of bars used for calculations")]
      		[GridCategory("Parameters")]
      		public int Box_Size
      		{
      			get { return BoxSize; }
      			set { BoxSize = Math.Max(1, value); }
      		}
              #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 PnFCount[] cachePnFCount = null;
      
              private static PnFCount checkPnFCount = new PnFCount();
      
              /// <summary>
              /// Enter the description of your new custom indicator here
              /// </summary>
              /// <returns></returns>
              public PnFCount PnFCount(int box_Size)
              {
                  return PnFCount(Input, box_Size);
              }
      
              /// <summary>
              /// Enter the description of your new custom indicator here
              /// </summary>
              /// <returns></returns>
              public PnFCount PnFCount(Data.IDataSeries input, int box_Size)
              {
                  if (cachePnFCount != null)
                      for (int idx = 0; idx < cachePnFCount.Length; idx++)
                          if (cachePnFCount[idx].Box_Size == box_Size && cachePnFCount[idx].EqualsInput(input))
                              return cachePnFCount[idx];
      
                  lock (checkPnFCount)
                  {
                      checkPnFCount.Box_Size = box_Size;
                      box_Size = checkPnFCount.Box_Size;
      
                      if (cachePnFCount != null)
                          for (int idx = 0; idx < cachePnFCount.Length; idx++)
                              if (cachePnFCount[idx].Box_Size == box_Size && cachePnFCount[idx].EqualsInput(input))
                                  return cachePnFCount[idx];
      
                      PnFCount indicator = new PnFCount();
                      indicator.BarsRequired = BarsRequired;
                      indicator.CalculateOnBarClose = CalculateOnBarClose;
      #if NT7
                      indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                      indicator.MaximumBarsLookBack = MaximumBarsLookBack;
      #endif
                      indicator.Input = input;
                      indicator.Box_Size = box_Size;
                      Indicators.Add(indicator);
                      indicator.SetUp();
      
                      PnFCount[] tmp = new PnFCount[cachePnFCount == null ? 1 : cachePnFCount.Length + 1];
                      if (cachePnFCount != null)
                          cachePnFCount.CopyTo(tmp, 0);
                      tmp[tmp.Length - 1] = indicator;
                      cachePnFCount = 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>
              /// Enter the description of your new custom indicator here
              /// </summary>
              /// <returns></returns>
              [Gui.Design.WizardCondition("Indicator")]
              public Indicator.PnFCount PnFCount(int box_Size)
              {
                  return _indicator.PnFCount(Input, box_Size);
              }
      
              /// <summary>
              /// Enter the description of your new custom indicator here
              /// </summary>
              /// <returns></returns>
              public Indicator.PnFCount PnFCount(Data.IDataSeries input, int box_Size)
              {
                  return _indicator.PnFCount(input, box_Size);
              }
          }
      }
      
      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
          public partial class Strategy : StrategyBase
          {
              /// <summary>
              /// Enter the description of your new custom indicator here
              /// </summary>
              /// <returns></returns>
              [Gui.Design.WizardCondition("Indicator")]
              public Indicator.PnFCount PnFCount(int box_Size)
              {
                  return _indicator.PnFCount(Input, box_Size);
              }
      
              /// <summary>
              /// Enter the description of your new custom indicator here
              /// </summary>
              /// <returns></returns>
              public Indicator.PnFCount PnFCount(Data.IDataSeries input, int box_Size)
              {
                  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.PnFCount(input, box_Size);
              }
          }
      }
      #endregion
      What is the exact issue that you are trying to resolve? Error message? Values not retained? What?

      Comment


        #4
        Image

        Sorry, attached is the exact error.

        The code loads fine and draws the count fine, but when I try to save it as a workspace I get this error. in order to have the indicator on my charts I have to load each time I load ninjatrader.

        Sody
        Attached Files
        Last edited by SodyTexas; 01-27-2015, 10:13 AM.

        Comment


          #5
          SodyTexas,

          This is because you have a public DataSeries variable and XML can't serialize it.

          You would want to use -
          Code:
          private DataSeries count;
          If you want a public series to access, then in the properties section below, use -
          Code:
          [XmlIgnore()]
          [Browsable(false)]
          public DataSeries Count
          {
          get { return Values[0]; }
          }
          Cal H.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Cal View Post
            SodyTexas,

            This is because you have a public DataSeries variable and XML can't serialize it.

            You would want to use -
            Code:
            private DataSeries count;
            If you want a public series to access, then in the properties section below, use -
            Code:
            [XmlIgnore()]
            [Browsable(false)]
            public DataSeries Count
            {
            get { return Values[0]; }
            }
            Thanks, updated code and it works.

            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 PnFCount : Indicator
                {
                    #region Variables
                    private int BoxSize = 7;
            		private DataSeries Count;
                    #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()
                    {
                        Overlay				= true;
            			Count = new DataSeries(this);
            			CalculateOnBarClose = false;
                    }
            
                    /// <summary>
                    /// Called on each bar update event (incoming tick)
                    /// </summary>
                    protected override void OnBarUpdate()
                    {
                        if(CurrentBar <= 4)return;
            			Count[0] = Math.Round((((High[0] - Low[0])/TickSize)/BoxSize)+1,0);
            			if (FirstTickOfBar)
            			{
            				Print("High: "+High[1]+" Low: "+Low[1]);
            			}
            			if(Open[0] < Close[0])
            			{
            				DrawText("count"+CurrentBar.ToString(),count[0].ToString(),0,Close[0]+(BoxSize*TickSize),Color.DimGray);
            			}
            			else
            			{
            				DrawText("count"+CurrentBar.ToString(),count[0].ToString(),0,Close[0]-(BoxSize*TickSize),Color.DimGray);
            			}
                    }
            
                    #region Properties
            		[Description("Numbers of bars used for calculations")]
            		[GridCategory("Parameters")]
            		public int Box_Size
            		{
            			get { return BoxSize; }
            			set { BoxSize = Math.Max(1, value); }
            		}
            		
            		[Browsable(false)]
            		[XmlIgnore()]
            		public DataSeries count
            		{
            			get { return Count; }
            		}
            		
                    #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 PnFCount[] cachePnFCount = null;
            
                    private static PnFCount checkPnFCount = new PnFCount();
            
                    /// <summary>
                    /// Enter the description of your new custom indicator here
                    /// </summary>
                    /// <returns></returns>
                    public PnFCount PnFCount(int box_Size)
                    {
                        return PnFCount(Input, box_Size);
                    }
            
                    /// <summary>
                    /// Enter the description of your new custom indicator here
                    /// </summary>
                    /// <returns></returns>
                    public PnFCount PnFCount(Data.IDataSeries input, int box_Size)
                    {
                        if (cachePnFCount != null)
                            for (int idx = 0; idx < cachePnFCount.Length; idx++)
                                if (cachePnFCount[idx].Box_Size == box_Size && cachePnFCount[idx].EqualsInput(input))
                                    return cachePnFCount[idx];
            
                        lock (checkPnFCount)
                        {
                            checkPnFCount.Box_Size = box_Size;
                            box_Size = checkPnFCount.Box_Size;
            
                            if (cachePnFCount != null)
                                for (int idx = 0; idx < cachePnFCount.Length; idx++)
                                    if (cachePnFCount[idx].Box_Size == box_Size && cachePnFCount[idx].EqualsInput(input))
                                        return cachePnFCount[idx];
            
                            PnFCount indicator = new PnFCount();
                            indicator.BarsRequired = BarsRequired;
                            indicator.CalculateOnBarClose = CalculateOnBarClose;
            #if NT7
                            indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                            indicator.MaximumBarsLookBack = MaximumBarsLookBack;
            #endif
                            indicator.Input = input;
                            indicator.Box_Size = box_Size;
                            Indicators.Add(indicator);
                            indicator.SetUp();
            
                            PnFCount[] tmp = new PnFCount[cachePnFCount == null ? 1 : cachePnFCount.Length + 1];
                            if (cachePnFCount != null)
                                cachePnFCount.CopyTo(tmp, 0);
                            tmp[tmp.Length - 1] = indicator;
                            cachePnFCount = 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>
                    /// Enter the description of your new custom indicator here
                    /// </summary>
                    /// <returns></returns>
                    [Gui.Design.WizardCondition("Indicator")]
                    public Indicator.PnFCount PnFCount(int box_Size)
                    {
                        return _indicator.PnFCount(Input, box_Size);
                    }
            
                    /// <summary>
                    /// Enter the description of your new custom indicator here
                    /// </summary>
                    /// <returns></returns>
                    public Indicator.PnFCount PnFCount(Data.IDataSeries input, int box_Size)
                    {
                        return _indicator.PnFCount(input, box_Size);
                    }
                }
            }
            
            // This namespace holds all strategies and is required. Do not change it.
            namespace NinjaTrader.Strategy
            {
                public partial class Strategy : StrategyBase
                {
                    /// <summary>
                    /// Enter the description of your new custom indicator here
                    /// </summary>
                    /// <returns></returns>
                    [Gui.Design.WizardCondition("Indicator")]
                    public Indicator.PnFCount PnFCount(int box_Size)
                    {
                        return _indicator.PnFCount(Input, box_Size);
                    }
            
                    /// <summary>
                    /// Enter the description of your new custom indicator here
                    /// </summary>
                    /// <returns></returns>
                    public Indicator.PnFCount PnFCount(Data.IDataSeries input, int box_Size)
                    {
                        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.PnFCount(input, box_Size);
                    }
                }
            }
            #endregion

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            18 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            1 view
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            6 views
            0 likes
            Last Post Javierw.ok  
            Started by timmbbo, Today, 08:59 AM
            2 responses
            10 views
            0 likes
            Last Post bltdavid  
            Started by alifarahani, Today, 09:40 AM
            6 responses
            41 views
            0 likes
            Last Post alifarahani  
            Working...
            X