Since NT only supports optimizing on integer and double parameters, all your optimizable parameters need to be of these types. The attached OptimizableProperty<T> class implements a generic property that can be treated as both an integer for exposing to NT optimization and a more natural type for the internals of your strategy. Currently it supports bool, enums, and TimeSpan types.
To create one, simply specify the type of property you desire in the angle brackets. E.g.:
public enum MovingAverageType { Simple, Exponential };
OptimizableProperty<MovingAverageType> maType = MovingAverageType.Simple;
OptimizableProperty<bool> fade = true;
You can then treat the property either as an integer or whatever type you specified in the angle brackets:
if (fade) {
...
}
if (maType == MovingAverageType.Exponential) {
...
}
...
public int Fade {
get { return fade; }
set { fade = value; }
}
public int MAType {
get { return maType; }
set { maType = value; }
}
Calling OptimizableProperty<T>.ToString() will return the natural string value of the property (e.g. 'true' or 'false' for OptimizableProperty<bool>).
The integer values for an OptimizableProperty<bool> are 0 (false) or 1 (true) while for an enum they range from 0 (the first enum value) to n-1 (the last value) where n is the number of values in the enum. For OptimizableProperty<TimeSpan> it is the number of minutes since midnight (the seconds portion is ignored).
Note that in some cases you will need to explicitly cast the OptimizableProperty<T> to either int or bool/enum/TimeSpan if the compiler is unable to automatically determine which type you want.
To install, copy the attached file to My Documents\NinjaTrader 6.5\bin\Custom\Type and compile a strategy once.
Comment