#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
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!
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
NinjaTrader
how to use observable collection.
Collapse
X
-
how to use observable collection.
i added a observable collection but the event is not firing up. Need some help here
Code:Tags: None
-
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
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by PaulMohn, Today, 12:36 PM
|
2 responses
16 views
0 likes
|
Last Post
by PaulMohn
Today, 01:48 PM
|
||
Started by Conceptzx, 10-11-2022, 06:38 AM
|
2 responses
53 views
0 likes
|
Last Post
by PhillT
Today, 01:47 PM
|
||
Started by Kaledus, Today, 01:29 PM
|
0 responses
3 views
0 likes
|
Last Post
by Kaledus
Today, 01:29 PM
|
||
Started by yertle, Yesterday, 08:38 AM
|
8 responses
37 views
0 likes
|
Last Post
by ryjoga
Today, 01:22 PM
|
||
Started by rdtdale, Today, 01:02 PM
|
1 response
6 views
0 likes
|
Last Post Today, 01:13 PM |
Comment