Parent: Steppable
The Parameter class represents a configurable value used throughout WealthLab, most commonly in C# Coded Strategies and custom indicators derived from IndicatorBase. Each Parameter has a Name, Type, Value, and DefaultValue. In C# Coded Strategies, Parameters can be optimized by defining MinValue, MaxValue, and StepValue. In custom indicators, Parameters define values that users can configure when working with the indicator in a chart or Building Block Strategy.
Returns the Parameter's Value as a BarHistory instance. This is intended for a Parameter whose Type is ParameterType.BarHistory.
Returns the Parameter's Value as a bool. This is intended for a Parameter whose Type is ParameterType.Boolean.
Returns the Parameter's Value as a WLColor instance. This is intended for a Parameter whose Type is ParameterType.Color.
Returns the Parameter's Value as a DataRange instance. This is intended for a Parameter whose Type is ParameterType.DataRange.
Returns the Parameter's Value as a DateTime. This is intended for a Parameter whose Type is ParameterType.Date.
Returns the Parameter's Value as a double. Int32 values are also converted to double.
Returns the Parameter's Value as a WLFont instance. This is intended for a Parameter whose Type is ParameterType.Font.
Returns the Parameter's Value as a HistoryScale instance. This is intended for a Parameter whose Type is ParameterType.HistoryScale.
Returns the Parameter's Value as an int. String values are parsed when possible, and double values are converted to int.
Returns the Parameter's Value as a LineStyle value.
Returns the Parameter's Value as a PriceComponent value.
Returns the Parameter's Value as a string. If the Value is an Enum, its string representation is returned. A null Value returns an empty string.
The first constructor creates a Parameter with the specified name, type, and initial value. The second additionally defines the MinValue, MaxValue, and StepValue used when the Parameter is optimized. The third constructor creates a ParameterType.StringChoice Parameter from an Enum type. Its Choices List is automatically populated with the names of the Enum values. In C# Coded Strategies you normally create Parameters using the AddParameter method of UserStrategyBase rather than instantiating Parameter directly. Custom indicators derived from IndicatorBase similarly provide an AddParameter method.
Assigns an explicit set of optimization values to the Parameter instead of deriving the values from MinValue, MaxValue, and StepValue. The first overload accepts an IEnumerable<double>, such as a List<double> or double array. The second accepts Int32 or double values directly. The values are sorted before being used.
using WealthLab.Backtest; using WealthLab.Core; namespace WealthScript { public class ExplicitValuesExample : UserStrategyBase { public ExplicitValuesExample() { Parameter p = AddParameter( "Explicit", ParameterType.Int32, 10, 10, 10000, 10); p.AssignExplicitValues(10, 20, 50, 100, 200); } public override void Initialize(BarHistory bars) { Parameter p = Parameters[0]; DrawHeaderText(p.ValuesDescription); } public override void Execute(BarHistory bars, int idx) { } } }
Assigns explicit optimization values consisting of the Fibonacci numbers that fall between the Parameter's MinValue and MaxValue. The Parameter must already have a defined minimum and maximum range.
using WealthLab.Backtest; using WealthLab.Core; namespace WealthScript { public class FibonacciValuesExample : UserStrategyBase { public FibonacciValuesExample() { Parameter p = AddParameter( "Fibonacci", ParameterType.Int32, 10, 10, 10000, 10); p.AssignFibonacciValues(); } public override void Initialize(BarHistory bars) { Parameter p = Parameters[0]; DrawHeaderText(p.ValuesDescription); } public override void Execute(BarHistory bars, int idx) { } } }
Assigns explicit optimization values beginning at MinValue, with each subsequent value increased by percentageGain percent. This is useful for producing logarithmically increasing optimization values. The Parameter must already have defined MinValue and MaxValue values, and percentageGain must be greater than zero.
using WealthLab.Backtest; using WealthLab.Core; namespace WealthScript { public class PercentageValuesExample : UserStrategyBase { public PercentageValuesExample() { Parameter p = AddParameter( "Percentage", ParameterType.Int32, 10, 10, 1000, 10); p.AssignPercentageValues(20); } public override void Initialize(BarHistory bars) { Parameter p = Parameters[0]; DrawHeaderText(p.ValuesDescription); } public override void Execute(BarHistory bars, int idx) { } } }
Contains the available choices for a Parameter whose Type is ParameterType.StringChoice. Add the desired strings to this collection when creating a StringChoice Parameter manually. The Enum-based Parameter constructor populates this List automatically.
Contains the initial value assigned when the Parameter was created. Unlike Value, DefaultValue is not changed when the Parameter is modified by an optimization or through the user interface.
Returns the available Parameter value that is closest to value. If no matching Parameter value can be found, the supplied value itself is returned.
Contains optional explanatory text for the Parameter. The hint is displayed as a tooltip when the user hovers over the Parameter in the Strategy Settings interface.
using WealthLab.Backtest; using WealthLab.Core; namespace WealthScript { public class ParameterHintExample : UserStrategyBase { public ParameterHintExample() { Parameter p = AddParameter( "Number of swings", ParameterType.Int32, 6, 1, 20, 1); p.Hint = "The number of swings used by the Strategy."; } public override void Initialize(BarHistory bars) { } public override void Execute(BarHistory bars, int idx) { } } }
Indicates whether the Parameter is enabled for optimization. The default value is true.
When true, prevents the Parameter's start, stop, and step values from being changed in the optimization parameter editor.
Indicates whether the Parameter should be made optimizable when it is used in a Building Block Strategy.
Contains the maximum value of the Parameter's optimization range.
Contains the minimum value of the Parameter's optimization range.
The descriptive name of the Parameter.
Contains the values that have been used to optimize this Parameter.
Returns the number of possible optimization values for the Parameter. If IsChecked is false, Permutations returns 1 because the Parameter does not contribute additional permutations to the optimization.
Returns a List<double> containing the possible values that the Parameter can assume.
Contains the increment used when generating optimization values. An optimization normally tests values beginning at MinValue, continuing through MaxValue, and incrementing by StepValue.
For a Parameter whose Type is ParameterType.StringChoice, returns the index in Choices of the currently selected value.
Specifies the data type represented by the Parameter's Value. See the Enums reference for the available ParameterType values.
Returns the name of the Parameter's type. For Parameters created from an Enum, TypeName is used to retain the Enum type information.
Validates the Parameter's optimization range. The method throws an InvalidOperationException if StepValue is zero or negative, or if MinValue is greater than MaxValue.
Contains the current value of the Parameter. The Value can differ from DefaultValue, for example when a Strategy Parameter is changed by the user or assigned a different value during an optimization.
Returns the numeric values that the Parameter can assume. Normally these values are generated from MinValue, MaxValue, and StepValue. If explicit values have been assigned using AssignExplicitValues, AssignFibonacciValues, or AssignPercentageValues, those values are returned instead.
using WealthLab.Backtest; using WealthLab.Core; namespace WealthScript { public class ParameterValuesExample : UserStrategyBase { public ParameterValuesExample() { AddParameter( "Param1", ParameterType.Int32, 20, 5, 100, 5); } public override void Initialize(BarHistory bars) { Parameter p = Parameters[0]; DrawHeaderText( "Parameter Permutations: " + p.Permutations); string values = ""; foreach (double value in p.Values) values += value + ","; DrawHeaderText( "Parameter Values: " + values); } public override void Execute(BarHistory bars, int idx) { } } }
Returns a textual description of the Parameter's available optimization values, including the number of values and a representation of the values themselves.