View Single Post
Old 03-23-2017, 10:05 AM   #1
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 26,241
Thanks: 493
Thanked 1,861 times in 1,793 posts
Default Indicator : Using a TypeConverter to Customize Property Grid Behavior

The default behavior of the NinjaTrader 8 property grid is designed to handle the most basic display of your custom Indicator and Strategy properties. However, there are special cases where you may want to control how unique properties display to other users. Since using a TypeConverter is more of a general C# concept used to convert values between data types (a string to an enum for example), so the possibilities of what you can do are within the bounds of the .NET Framework. This NinjaScript sample was produced to help NinjaScript developers understand how to leverage the IndicatorBaseConverter and StrategyBaseConverter helper classes to customize property grid behavior without affecting general NinjaTrader 8 property behavior.

Note:
  • NinjaTrader 8 expects custom properties to be of value type or type which implements ICloneable interface
  • This reference sample assumes you are familiar with basic C# TypeConverter practices and is intended as a starting point. There are extensive 3rd party guides available online which can help you implement a particular type converter goal not covered in this sample

Key concepts in this example:

There are 5 use cases demonstrated in this sample which fall into two different categories:

1. Dynamically manipulate what is displayed on the UI Property Grid
  1. Show / hide properties based on secondary input
  2. Disable / enable properties based on secondary input

2. Customizing how a property is displayed
  1. Display "Friendly" enum values
  2. Re-implement a "bool" CheckBox as "Friendly" a ComboBox
  3. Display a custom collection / list with user defined values at run time

Important related documentation:

C#

NinjaTrader 8

IndicatorBaseConverter Class
StrategyBaseConverter Class
TypeConverterAttribute


Note: The reference sample files on this page are written for an indicator using the IndicatorBaseConverter class, but the same key concepts are available to strategies by replacing the StrategyBaseConverter where noted in the sample code

NinjaTrader 7

Not applicable

Import instructions:

NinjaTrader 8
  1. Download the file contained in this thread to your PC desktop
  2. From the Control Center window, select the menu Tools > Import > NinjaScript Add-On
  3. Select the downloaded zip file

Additional resources:
MSDN - How to: Implement a Type Converter
Attached Files
File Type: zip SampleIndicatorTypeConverter_NT8.zip (5.5 KB, 40 views)
Last edited by NinjaTrader_Bertrand; 01-04-2018 at 11:47 AM.
NinjaTrader_Bertrand is offline  
Reply With Quote
The following 6 users say thank you to NinjaTrader_Bertrand for this post: