• 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

how to use observable collection.

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

    how to use observable collection.

    i added a observable collection but the event is not firing up. Need some help here
    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
    
    using System.Collections.ObjectModel;
    using System.Collections.Specialized;
    // 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 IndicatorObservablecolleciton : Indicator
        {
            #region Variables
            // Wizard generated variables
                private int myInput0 = 1; // Default setting for MyInput0
            // User defined variables (add any user defined variables below)
    		ObservableCollection<string> mylist = new ObservableCollection<string>();
            #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.Orange), PlotStyle.Line, "Plot0"));
                Overlay				= false;
    			 CalculateOnBarClose = false;
    			 mylist.CollectionChanged  += names_CollectionChanged;
            }
    
            /// <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.
                Plot0.Set(Close[0]);
    			if(FirstTickOfBar)
    			{
    				mylist.Add(CurrentBar.ToString());
    			}
    			
            }
    		private  void names_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
    	Print("Change type: " + e.Action);
        if (e.NewItems != null)
        {
            Print("Items added: ");
            foreach (var item in e.NewItems)
            {
                Print(item.ToString());
            }
        }
     
        if (e.OldItems != null)
        {
            Print("Items removed: ");
            foreach (var item in e.OldItems)
            {
                Print(item.ToString());
            }
        }
    }
    
    
            #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]; }
            }
    		
    		 public ObservableCollection<string>  customvalues
            {
                get { return mylist; }
            }
    
            [Description("")]
            [GridCategory("Parameters")]
            public int MyInput0
            {
                get { return myInput0; }
                set { myInput0 = 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 IndicatorObservablecolleciton[] cacheIndicatorObservablecolleciton = null;
    
            private static IndicatorObservablecolleciton checkIndicatorObservablecolleciton = new IndicatorObservablecolleciton();
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public IndicatorObservablecolleciton IndicatorObservablecolleciton(int myInput0)
            {
                return IndicatorObservablecolleciton(Input, myInput0);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public IndicatorObservablecolleciton IndicatorObservablecolleciton(Data.IDataSeries input, int myInput0)
            {
                if (cacheIndicatorObservablecolleciton != null)
                    for (int idx = 0; idx < cacheIndicatorObservablecolleciton.Length; idx++)
                        if (cacheIndicatorObservablecolleciton[idx].MyInput0 == myInput0 && cacheIndicatorObservablecolleciton[idx].EqualsInput(input))
                            return cacheIndicatorObservablecolleciton[idx];
    
                lock (checkIndicatorObservablecolleciton)
                {
                    checkIndicatorObservablecolleciton.MyInput0 = myInput0;
                    myInput0 = checkIndicatorObservablecolleciton.MyInput0;
    
                    if (cacheIndicatorObservablecolleciton != null)
                        for (int idx = 0; idx < cacheIndicatorObservablecolleciton.Length; idx++)
                            if (cacheIndicatorObservablecolleciton[idx].MyInput0 == myInput0 && cacheIndicatorObservablecolleciton[idx].EqualsInput(input))
                                return cacheIndicatorObservablecolleciton[idx];
    
                    IndicatorObservablecolleciton indicator = new IndicatorObservablecolleciton();
                    indicator.BarsRequired = BarsRequired;
                    indicator.CalculateOnBarClose = CalculateOnBarClose;
    #if NT7
                    indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                    indicator.MaximumBarsLookBack = MaximumBarsLookBack;
    #endif
                    indicator.Input = input;
                    indicator.MyInput0 = myInput0;
                    Indicators.Add(indicator);
                    indicator.SetUp();
    
                    IndicatorObservablecolleciton[] tmp = new IndicatorObservablecolleciton[cacheIndicatorObservablecolleciton == null ? 1 : cacheIndicatorObservablecolleciton.Length + 1];
                    if (cacheIndicatorObservablecolleciton != null)
                        cacheIndicatorObservablecolleciton.CopyTo(tmp, 0);
                    tmp[tmp.Length - 1] = indicator;
                    cacheIndicatorObservablecolleciton = 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.IndicatorObservablecolleciton IndicatorObservablecolleciton(int myInput0)
            {
                return _indicator.IndicatorObservablecolleciton(Input, myInput0);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public Indicator.IndicatorObservablecolleciton IndicatorObservablecolleciton(Data.IDataSeries input, int myInput0)
            {
                return _indicator.IndicatorObservablecolleciton(input, myInput0);
            }
        }
    }
    
    // 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.IndicatorObservablecolleciton IndicatorObservablecolleciton(int myInput0)
            {
                return _indicator.IndicatorObservablecolleciton(Input, myInput0);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public Indicator.IndicatorObservablecolleciton IndicatorObservablecolleciton(Data.IDataSeries input, int myInput0)
            {
                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.IndicatorObservablecolleciton(input, myInput0);
            }
        }
    }
    #endregion

    #2
    Hello,

    I tried the script and see the event working:

    Change type: Add
    Items added:
    5038
    Change type: Add
    Items added:
    5039
    Change type: Add
    Items added:
    5040
    Change type: Add
    Items added:
    5041


    Can you tell me, are you seeing any errors or the script is just not printing anything for you? Have you tried completely removing the instance of the script and re adding it to a chart as well?

    Additionally, this would require a reference to WindowsBase.dll, how was this reference added and also had you restarted the platform after adding the reference?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      yes it works. i was not using the right indicator when i tested it

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Lucas9435, Today, 08:12 AM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_ChrisL  
      Started by mrtorture, Today, 08:11 AM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_Heath  
      Started by Aporshnev, Today, 07:55 AM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_PatrickG  
      Started by tonynt, Today, 08:12 AM
      0 responses
      2 views
      0 likes
      Last Post tonynt
      by tonynt
       
      Started by tff2011, Yesterday, 03:55 PM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X