I have a property data class that I'm using in my indicator and would like those properties to be editable directly in the indicator dialog window. I've been able to get things to "mostly" work, however I keep getting an error when the code base is rebuilt.
Error on getting/setting property 'X' for NinjaScript 'CopyProblemDemo': Object of type 'NinjaTrader.NinjaScript.Indicators.Foo' cannot be converted to type 'NinjaTrader.NinjaScript.Indicators.Foo'.
My best guess is there is an assembly version mismatch happening here, but I'm not sure how to fix it.
Does anyone know the correct approach here?
Thank you,
Mark
-------------------------------------------------------
To Reproduce:
1) Compile CopyProblemDemo indicator code
2) add CopyProblemDemo indicator to a chart
3) Compile the indicator again
4) on the chart with the indicator, press f-5 to refresh
namespace NinjaTrader.NinjaScript.Indicators { [TypeConverter("NinjaTrader.NinjaScript.Indicators. FooTypeConverter")] public class Foo : ICloneable { public int A {set;get;} public int B {set;get;} public object Clone() { Foo x = new Foo(); CopyTo(x); return x; } public void CopyTo(Foo other) { if(other==null){return;} other.A = A; other.B = B; } public override string ToString() { return string.Format("A={0} B={1}",A,B); } } public class FooTypeConverter : TypeConverter { public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs) { if (component == null) { return null; } Foo foo = component as Foo; PropertyDescriptorCollection propertyDescriptorCollection = base.GetPropertiesSupported(context) ? base.GetProperties(context, component, attrs) : TypeDescriptor.GetProperties(component, attrs); if (foo == null || propertyDescriptorCollection == null) return null; PropertyDescriptorCollection filtered = new PropertyDescriptorCollection(null); foreach (PropertyDescriptor property in propertyDescriptorCollection) { if (property.IsBrowsable) filtered.Add(property); } return filtered; } public override bool GetPropertiesSupported(ITypeDescriptorContext context) { return true; } } public class CopyProblemDemo : Indicator { public Foo X {set;get;} protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @""; Name = "CopyProblemDemo"; Calculate = Calculate.OnBarClose; IsOverlay = false; DisplayInDataBox = true; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; //Disable this property if your indicator requires custom values that cumulate with each new market data event. //See Help Guide for additional information. IsSuspendedWhileInactive = true; X = new Foo(); } else if (State == State.Configure) { } } protected override void OnBarUpdate() { //Add your custom indicator logic here. } } }
Comment