IndicatorBaseConverter RenkoTrader Ninjatrader
https://pastecode.io/s/2mj8xbbw https://pastecode.io/s/ow7sge2r https://pastecode.io/s/2mj8xbbw https://ninjatraderecosystem.com/user-app-share-download/renko-trader-bot-semi-automatic-with-interface-and-higher-time-frame-filter/unknown
csharp
9 months ago
3.5 kB
25
No Index
#region Show/Hide Inputs Converter // This custom TypeConverter is applied ot the entire strategy object and handles two of our use cases // IMPORTANT: Inherit from StrategyBaseConverter so we get default NinjaTrader property handling logic // IMPORTANT: Not doing this will completely break the property grids! // If targeting a "Strategy", use the "StrategyBaseConverter" base type instead public class RenkoTrader_Converter : IndicatorBaseConverter // or StrategyBaseConverter { public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs) { // we need the strategy instance which actually exists on the grid RenkoTrader indicator = component as RenkoTrader; // base.GetProperties ensures we have all the properties (and associated property grid editors) // NinjaTrader internal logic determines for a given strategy PropertyDescriptorCollection propertyDescriptorCollection = base.GetPropertiesSupported(context) ? base.GetProperties(context, component, attrs) : TypeDescriptor.GetProperties(component, attrs); if (indicator == null || propertyDescriptorCollection == null) return propertyDescriptorCollection; #region Use Case #1: Show/hide properties based on secondary input System.Reflection.PropertyInfo[] props = typeof(RenkoTrader).GetProperties(); foreach (System.Reflection.PropertyInfo prop in props) { object[] attributes = prop.GetCustomAttributes(true); foreach (object a in attributes) { IvAttributes.IvShowHideAttribute customAttribute = a as IvAttributes.IvShowHideAttribute; if (customAttribute != null) { string[] propNames = customAttribute.PropertyName.Split('|'); string[] propResults = customAttribute.PropertyResult.Split('|'); for (int i = 0; i < propNames.Length; i++) { string[] OrResults = propResults[i].Split('/'); string[] NorResults = propResults[i].Split('!'); Object mainProp = indicator.GetType().GetProperty(propNames[i]).GetValue(indicator, null); if (((mainProp.ToString() != propResults[i] && OrResults.Length == 1) || (OrResults.Length > 0 && OrResults.All(x => x != mainProp.ToString()))) && (NorResults.Length == 1 || NorResults.Any(x => x == mainProp.ToString())) ) { propertyDescriptorCollection.Remove(propertyDescriptorCollection[prop.Name]); } } } } } #endregion return propertyDescriptorCollection; } // Important: This must return true otherwise the type convetor will not be called public override bool GetPropertiesSupported(ITypeDescriptorContext context) { return true; } } #endregion
Editor is loading...
Leave a Comment