I have a very basic custom indicator that has no additional custom dependencies other than one custom enumeration:
public enum InstrumentInfoItem { DaysToNextRollover, InstrumentType, IsFuture, IsForex, IsIndex, IsStock, NextExpiryMonth, PointValue, TickSize, TickValue }
[NinjaScriptProperty] [Display(Name = "Info to Display", Description = "The type of information to display.", GroupName = "Parameters", Order = 0)] public InstrumentInfoItem InfoItem { get; set; }
I've tried putting the enumeration a variety of places. My preference is to just put it in the indicator cs file in the same namespace as the indicator:
namespace NinjaTrader.NinjaScript.Indicators.NinjaMastery.Info { public enum InstrumentInfoItem { DaysToNextRollover, InstrumentType, IsFuture, IsForex, IsIndex, IsStock, NextExpiryMonth, PointValue, TickSize, TickValue } /// <summary> /// Bars since last entry /// Days since last entry /// IsFlat /// </summary> public class NinjaMastery_InstrumentInfo : Indicator { ....
- AddOns folder
- Indicator cs file but in NinjaTrader.NinjaScript.Indicators namespace
- Separate DLL
The export completes successfully, but then when importing on the other machine I get the error that the enum cannot be found.
This immediately looks like a missing using directive or something similar.
What Appears to Be Causing the Problem
The problem appears to be in the .cs file in the zip that is generated during the export which contains the autogenerated partial classes.
The namespaces in this cs file are some default set of namespaces and do not reflect the namespaces in my indicator file.
#region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Gui.Tools; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; #endregion
The same problem occurs if I put the enum in the AddOns folder. Unless I were to put the enum in one of the above namespaces, it can't be resolved.
I'm thinking the .cs file in the zip should actually include the namespace of the indicator class at a minimum. And if it were really smart it would also include the namespaces of any "AddOn" code included in the export to be sure that could be resolved.
For example,
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.Indicators.Folder1.Folder2;
When I manually modify the cs file in the zip to include the namespace of the enum then everything works fine.
My Questions
Am I missing something obvious? Is there another way to do this? Is it known that in a circumstance like this that you would just need to manually include the needed namespace?
Seems to me that an excellent approach would be to have NT automatically insert the indicator namespace (and possibly the addon namespaces) in the cs file during export.
I suppose it's possible that you intended to not support the use of enums as indicator NinjaScriptProperties, but they work great and I can't imagine a reason to disallow them.
Thanks,
Steve
Comment