Parent: Object
Represents the position sizing settings established for a backtest. PositionSize defines the sizing method and amount, starting capital, margin factor, maximum open positions, maximum entry signals per bar, and optional advanced PositionSizer. It also contains the settings used when optimizing position sizing parameters.
Determines how the basis price used for position sizing is established. When false, which is the default, the basis price is based on the closing price of the signal bar. If the market gaps on the following bar, the actual cost of the trade can exceed the amount available and potentially cause the simulated trade to receive NSF status. When true, the basis price is based on the open price of the following bar. This can avoid NSF results caused by opening gaps, but assumes that the execution environment can accommodate the resulting position size.
The parameterless constructor creates a PositionSize configured to use 5% of equity, $100,000 starting capital, and a margin factor of 1.0. The second constructor creates a PositionSize using the specified pst sizing method and amt amount. StartingCapital defaults to $100,000 and MarginFactor to 1.0.
Returns true if obj is a PositionSize whose primary backtest sizing settings are equal to this instance. The comparison includes StartingCapital, PositionSizeType, Amount, MarginFactor, UseNextBarOpenAsBasisPrice, and MaxOpenPositions.
Returns a hash code for the PositionSize based on its string representation.
Returns true if the two PositionSize instances do not have equal primary sizing settings.
Returns true if the two PositionSize instances have equal primary sizing settings. The comparison includes StartingCapital, PositionSizeType, Amount, MarginFactor, UseNextBarOpenAsBasisPrice, and MaxOpenPositions. The operator also handles null PositionSize references.
Returns a concise description of the PositionSize suitable for display or debugging. The format depends on PositionSizeType. Examples include:
Value=5,000.00Shares=100% Equity=5.00%Max Risk=2.00%PosSizer=Position Sizer NameIf MaxSignalsPerBar is greater than zero, the maximum entry count is appended to the string.
Gets or sets whether the position sizing Amount is enabled for optimization. The optimization range used depends on PositionSizeType.
Applies the optimization settings represented by Parameter p to one of the built-in PositionSize parameters. The tag identifies the PositionSize parameter:
- 0 - StartingCapital
- 1 - Amount
- 2 - MarginFactor
- 3 - MaxOpenPositions When assignValue is true, the Parameter's current value is also assigned to the corresponding PositionSize property.
Applies optimized values from the specified ParameterList to this PositionSize. Built-in PositionSize parameters are identified by their PositionSize optimization tags. When an advanced PositionSizer is being used, matching optimized PositionSizer Parameters are also updated.
Gets or sets the optimization range used for Amount when PositionSizeType is PositionSizeType.Dollar. The default range is 1,000 through 10,000 in steps of 1,000.
Gets or sets the optimization range used for Amount when PositionSizeType is PositionSizeType.Quantity. The default range is 100 through 1,000 in steps of 100.
Returns a ParameterList containing the PositionSize parameters currently enabled for optimization. If PositionSizeType is PositionSizeType.PosSizer, optimizable Parameters belonging to the advanced PositionSizer are also included.
Returns true if any PositionSize parameter is enabled for optimization. This includes StartingCapOpt, AmountOpt, MarginOpt, MaxOpenPosOpt, or an optimizable Parameter belonging to an advanced PositionSizer. :contentReference[oaicite:0]
Gets or sets whether MarginFactor is enabled for optimization.
Gets or sets the optimization range for MarginFactor. The default range is 1.0 through 2.0 in steps of 0.1.
Gets or sets whether MaxOpenPositions is enabled for optimization.
Gets or sets the optimization range for MaxOpenPositions. The default range is 1 through 1,000 in steps of 1.
Gets or sets the optimization range used for Amount when PositionSizeType is PositionSizeType.MaxRiskPct. The default range is 5% through 50% in steps of 5%.
Gets or sets the optimization range used for Amount when PositionSizeType is PositionSizeType.PctOfEquity. The default range is 1% through 20% in steps of 1%.
Gets or sets whether StartingCapital is enabled for optimization.
Gets or sets the optimization range for StartingCapital. The default range is 50,000 through 200,000 in steps of 10,000.
Returns a new PositionSize containing a copy of the current settings. When using an advanced PositionSizer, the PositionSizer and its Parameters are also cloned. Optimization settings and their Steppable ranges are copied to the new instance.
Creates and returns a PositionSize by parsing the persisted representation specified in s. The method also supports legacy PositionSize persistence formats. If a persisted advanced PositionSizer cannot be created, PositionSizeType is changed to PositionSizeType.Dollar.
Returns a string containing a serialized representation of the PositionSize settings. The persisted data includes the sizing type and amount, starting capital, margin factor, advanced PositionSizer information when applicable, maximum open Positions, basis-price setting, optimization settings, maximum Signals per bar, and optimization ranges.
Returns true when MaxOpenPositions is greater than zero.
Gets or sets the maximum number of Positions that can be open simultaneously during the backtest. A value of zero indicates no limit.
Gets or sets the maximum number of entry Signals that can be generated on a single bar. A value of zero indicates no limit.
Gets or sets the amount used by the position sizing method. The meaning of Amount depends on PositionSizeType:
- Dollar - Fixed currency amount.
- Quantity - Fixed number of shares or contracts.
- PctOfEquity - Percentage of current simulated equity.
- MaxRiskPct - Percentage of current simulated equity to risk based on the Strategy's risk stop level.
- PosSizer - Position sizing is controlled by the PositionSizer instance.
Gets or sets the margin factor used by the backtest. The value must be at least 1.0. Attempts to assign a smaller value are ignored.
Gets or sets the PositionSizerBase instance used when PositionSizeType is PositionSizeType.PosSizer.
Gets or sets the name of the advanced PositionSizer. This property is used when serializing PositionSize.
Gets or sets the serialized ParameterList for the advanced PositionSizer. This property is used when serializing PositionSize.
Gets or sets the position sizing method. Possible PositionSizeType values include:
- Dollar - Uses a fixed currency amount.
- Quantity - Uses a fixed number of shares or contracts.
- PctOfEquity - Uses a percentage of current simulated equity.
- MaxRiskPct - Risks a percentage of current simulated equity based on the Strategy's risk stop level.
- PosSizer - Uses a PositionSizerBase instance for advanced position sizing.
Gets or sets the starting capital for the backtest.