| 1 | // This namespace holds Indicators in this folder and is required. Do not change it. |
| 2 | namespace NinjaTrader.NinjaScript.Indicators |
| 3 | { |
| 4 | // When applying the type converter, you must fully qualify the name |
| 5 | [TypeConverter("NinjaTrader.NinjaScript.Indicators.MyCustomConveter")] |
| 6 | public class MyCustomIndicator : Indicator |
| 7 | { |
| 8 | protected override void OnStateChange() |
| 9 | { |
| 10 | if (State == State.SetDefaults) |
| 11 | { |
| 12 | Name = "MyCustomIndicator"; |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | protected override void OnBarUpdate() |
| 17 | { |
| 18 | // Add your custom indicator logic here. |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | public class MyCustomConveter : IndicatorBaseConverter |
| 23 | { |
| 24 | // A general TypeConveter method used for converting types |
| 25 | public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs) |
| 26 | { |
| 27 | // sometimes you may need the indicator instance which actually exists on the grid |
| 28 | MyCustomIndicator indicator = component as MyCustomIndicator; |
| 29 | |
| 30 | // base.GetProperties ensures we have all the properties (and associated property grid editors) |
| 31 | // NinjaTrader internal logic handles for a given indicator |
| 32 | PropertyDescriptorCollection propertyDescriptorCollection = base.GetPropertiesSupported(context) |
| 33 | ? base.GetProperties(context, component, attrs) : TypeDescriptor.GetProperties(component, attrs); |
| 34 | |
| 35 | if (indicator == null || propertyDescriptorCollection == null) |
| 36 | return propertyDescriptorCollection; |
| 37 | |
| 38 | // example of why you may need the instance that exists on the grid.... |
| 39 | if (indicator.EntryHandling == EntryHandling.UniqueEntries) |
| 40 | { |
| 41 | // do something in the event a property contains some value... |
| 42 | } |
| 43 | |
| 44 | // Loop all of the properties of the indicator |
| 45 | foreach (PropertyDescriptor property in propertyDescriptorCollection) |
| 46 | { |
| 47 | // do something with a specific property |
| 48 | |
| 49 | // cannot call **Print()** here |
| 50 | // but you can call the static Output window "Process()" |
| 51 | NinjaTrader.Code.Output.Process(property.Name, PrintTo.OutputTab1); |
| 52 | } |
| 53 | |
| 54 | // must return the collection after making changes |
| 55 | return propertyDescriptorCollection; |
| 56 | } |
| 57 | |
| 58 | // Important: This must return true otherwise the type converter will not be called |
| 59 | public override bool GetPropertiesSupported(ITypeDescriptorContext context) |
| 60 | { return true; } |
| 61 | } |
| 62 | } |