Parameters

Strategies

Parameters

Expose tunable inputs — periods, risk multiples, toggles, labels, file paths — some of which the optimizer can sweep, all of which the host applies before your logic runs.

Parameters

A strategy parameter is an input the host supplies before the run starts: a number, a flag, a string, a file path. You declare them in OnInitialize using the *Parameter helpers, store the returned handle in a field, and read .Value wherever you need it. There are two flavours, and the difference matters for optimization.

Only the numeric helpers can be optimized. IntParameter and DoubleParameter each have an extra overload taking (name, default, min, max, step) — that optimizable form lets the Strategy Analyzer sweep the value across the declared range during a parameter search. Their plain (name, default) form, and BoolParameter, StringParameter and FilePathParameter, are fixed configuration: the user can set them but the optimizer will not vary them.

C#protected override void OnInitialize()
{
    _period   = IntParameter("Period", 20, 5, 200, 1);          // optimizable int
    _riskR    = DoubleParameter("RiskR", 2.0, 0.5, 5.0, 0.5);   // optimizable double
    _maxPos   = IntParameter("MaxPositions", 3);                // fixed int (no sweep)
    _useTrail = BoolParameter("UseTrail", true);               // toggle
    _label    = StringParameter("Label", "swing");            // free text
    _plan     = FilePathParameter("Plan", "", "Plans (*.json)|*.json"); // Browse button
}

protected override void OnBar()
{
    int n = _period.Value;   // or: int n = _period;  (implicit conversion to T)
    if (_useTrail.Value) { /* ... */ }
}
Helper Type Optimizable Editor
IntParameter(name, default, min, max, step) int Yes Numeric
IntParameter(name, default) int No Numeric
DoubleParameter(name, default, min, max, step) double Yes Numeric
DoubleParameter(name, default) double No Numeric
BoolParameter(name, default) bool No Checkbox
StringParameter(name, default) string No Textbox
FilePathParameter(name, default, fileFilter) string No Path + Browse
Override flow. Defaults are declared in OnInitialize; the host applies any ParameterOverrides after OnInitialize and before OnStart; the optimizer drives a different override map per run. A key that matches no declared parameter, or a value that cannot be coerced to the parameter's type, is logged and skipped — the parameter keeps its default rather than faulting the run. Parameters are inputs, not mutable state: a strategy never writes .Value itself.

Optimization ranges

The optimizable overloads build an OptimizationRange(Min, Max, Step) — a record stored in decimal so user-specified steps (0.5, 0.25, …) stay exact rather than drifting across a sweep. Its Validated(name) guard rejects a backwards range (Min > Max) or a non-positive step. The host reads it through the parameter's IsOptimizable and OptimizationRange properties to build a sweep.

The parameter handle & the set

Each helper returns a typed StrategyParameter<T> with Value, DefaultValue, ValueType and an implicit conversion to T. Its abstract base StrategyParameter is the non-generic facet the host enumerates: Name (unique case-insensitively within a strategy), IsOptimizable, OptimizationRange, EditorKind (a ParameterEditorKindAuto by default, FilePicker for a path), FileFilter, and the boxed BoxedValue.

The whole collection is a ParameterSetAll (declaration order), Count, Find(name) and TrySetValue(name, value) — which is exactly how the host and the optimizer apply an override map without knowing your concrete type. You reach the set through the descriptor's Parameters (see the catalog API); a strategy itself just reads its handles.

Duplicate names fault the run. Declaring two parameters whose names differ only in case throws at declaration time — it is a strategy bug, surfaced loudly rather than silently aliased.