AsBarHistory
public BarHistory AsBarHistoryReturns the Parameter's Value as a BarHistory instance. This is intended for a Parameter whose Type is ParameterType.BarHistory.
API documentation, members, signatures, and C# examples.
Find classes, members, and documentation.
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.
public BarHistory AsBarHistoryReturns the Parameter's Value as a BarHistory instance. This is intended for a Parameter whose Type is ParameterType.BarHistory.
public bool AsBooleanReturns the Parameter's Value as a bool. This is intended for a Parameter whose Type is ParameterType.Boolean.
public WLColor AsColorReturns the Parameter's Value as a WLColor instance. This is intended for a Parameter whose Type is ParameterType.Color.
public DataRange AsDataRangeReturns the Parameter's Value as a DataRange instance. This is intended for a Parameter whose Type is ParameterType.DataRange.
public DateTime AsDateReturns the Parameter's Value as a DateTime. This is intended for a Parameter whose Type is ParameterType.Date.
public double AsDoubleReturns the Parameter's Value as a double. Int32 values are also converted to double.
public WLFont AsFontReturns the Parameter's Value as a WLFont instance. This is intended for a Parameter whose Type is ParameterType.Font.
public HistoryScale AsHistoryScaleReturns the Parameter's Value as a HistoryScale instance. This is intended for a Parameter whose Type is ParameterType.HistoryScale.
public int AsIntReturns the Parameter's Value as an int. String values are parsed when possible, and double values are converted to int.
public LineStyle AsLineStyleReturns the Parameter's Value as a LineStyle value.
public PriceComponent AsPriceComponentReturns the Parameter's Value as a PriceComponent value.
public string AsStringReturns 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.
public TimeSeries AsTimeSeriesReturns the Parameter's Value as a TimeSeries instance.
public Parameter(string name, ParameterType type, object value)public Parameter(string name, ParameterType type, object value, double minValue, double maxValue, double stepValue = 1.0)public Parameter(string name, Type enumType)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.
public void AssignExplicitValues(IEnumerable<double> values)public void AssignExplicitValues(params object[] vals)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)
{
}
}
}
public void AssignFibonacciValues()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)
{
}
}
}
public void AssignPercentageValues(double percentageGain)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)
{
}
}
}
public List<string> ChoicesContains 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.
public object DefaultValueContains 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.
public double FindClosestMatch(double value)Returns the available Parameter value that is closest to value. If no matching Parameter value can be found, the supplied value itself is returned.
public string HintContains 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)
{
}
}
}
public bool IsCheckedIndicates whether the Parameter is enabled for optimization. The default value is true.
public bool IsReadOnlyWhen true, prevents the Parameter's start, stop, and step values from being changed in the optimization parameter editor.
public bool MakeOptimizableIndicates whether the Parameter should be made optimizable when it is used in a Building Block Strategy.
public double MaxValueContains the maximum value of the Parameter's optimization range.
public double MinValueContains the minimum value of the Parameter's optimization range.
public string NameThe descriptive name of the Parameter.
public UniqueList<double> OptimizedValuesContains the values that have been used to optimize this Parameter.
public ulong PermutationsReturns 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.
public List<double> PossibleValuesReturns a List<double> containing the possible values that the Parameter can assume.
public double StepValueContains the increment used when generating optimization values. An optimization normally tests values beginning at MinValue, continuing through MaxValue, and incrementing by StepValue.
public int StringChoiceIndexFor a Parameter whose Type is ParameterType.StringChoice, returns the index in Choices of the currently selected value.
public ParameterType TypeSpecifies the data type represented by the Parameter's Value. See the Enums reference for the available ParameterType values.
public string TypeNameReturns the name of the Parameter's type. For Parameters created from an Enum, TypeName is used to retain the Enum type information.
public void ValidateStartStopStep()Validates the Parameter's optimization range. The method throws an InvalidOperationException if StepValue is zero or negative, or if MinValue is greater than MaxValue.
public object ValueContains 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.
public List<double> ValuesReturns 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)
{
}
}
}
public string ValuesDescriptionReturns a textual description of the Parameter's available optimization values, including the number of values and a representation of the values themselves.
Ask the community or explore custom development services.