Parent: Object
The BacktestSettings class contains the settings and preferences that control how WealthLab 9 conducts a backtest, including commissions, slippage, interest, dividends, futures handling, position matching, signal ordering, and multi-currency simulation.
Controls how WealthLab counts the holding period of Positions that exit using a Market order at the market open. Set this to true to count the market-exit bar as a full bar for holding-period calculations.
Specifies the priority WealthLab uses when sorting competing exit orders.
Specifies the intraday HistoryScale WealthLab uses for granular processing of Limit and Stop entry Signals. The default is HistoryScale.Daily, which disables granular intraday processing. This setting is not included in the normal persisted BacktestSettings string.
Specifies how WealthLab sorts the final set of Signals generated by the Backtester. Possible values are:
- Symbol
- TransTypeSymbol
- TransTypeWeightSymbol
If set to true, WealthLab uses commission settings defined for the applicable Market or Symbol instead of relying exclusively on the general BacktestSettings commission configuration.
The annual percentage rate of interest earned on positive simulated cash balances. This value is ignored when UseUSTRateAsInterest is true.
If set to true, simulated dividends are collected during the backtest. WealthLab obtains dividend information from EventDataPoint instances associated with the BarHistory data.
Returns a Commission instance configured from CommissionType, CommissionAmount, and the optional minimum and maximum commission settings. You can also assign a custom Commission instance to override the Commission generated from these properties.
Specifies the commission amount used during the backtest. The interpretation of this value depends on CommissionType.
Specifies the commission method used during the backtest.
If set to true, WealthLab uses futures-specific SymbolInfo values such as Margin, PointValue, and TickSize when performing applicable backtest calculations.
Controls how WealthLab calculates futures profit when Futures Mode is active. When true, futures profit calculations use the futures margin-based behavior. When false, WealthLab uses the raw position value behavior.
Returns the global BacktestSettings instance used by WealthLab 9.
If set to true, WealthLab applies simulated slippage to Limit orders. The amount is controlled by SlippagePercentStocks for stocks and SlippageTickFutures for futures.
If set to true, WealthLab applies simulated slippage to applicable Market, Stop, and AtClose orders. The amount is controlled by SlippagePercentStocks for stocks and SlippageTickFutures for futures.
The annual percentage rate charged on simulated margin balances.
Specifies the maximum commission that can be charged for a Transaction when UseMaximumCommission is true.
Specifies the minimum commission that can be charged for a Transaction when UseMinimumCommission is true.
Controls whether WealthLab retains Positions for which there was insufficient simulated capital or buying power to complete the fill. When true, these NSF Positions continue to participate in Strategy logic so that their eventual exit conditions and Signals can still be generated. Setting this to false can reduce backtest overhead, but can also alter subsequent Strategy behavior because the NSF Position is no longer considered open. This setting is an Advanced Strategy setting and is not included in the normal persisted BacktestSettings string.
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript { public class MyStrategy : UserStrategyBase { public override void Initialize(BarHistory bars) { BacktestSettings.RetainNSFPositions = false; StartIndex = 13; _sma1 = SMA.Series(bars.Close, 8); _sma2 = SMA.Series(bars.Close, 13); PlotIndicatorLine(_sma1, WLColor.Blue); PlotIndicatorLine(_sma2, WLColor.Red); } public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { if (_sma1.CrossesOver(_sma2, idx)) PlaceTrade(bars, TransactionType.Buy, OrderType.Market); } else { if (_sma1.CrossesUnder(_sma2, idx)) PlaceTrade(bars, TransactionType.Sell, OrderType.Market); } } IndicatorBase _sma1; IndicatorBase _sma2; } }
If set to true, WealthLab applies round-lot sizing rules to Transaction quantities.
Specifies the percentage slippage applied to stock Transactions when slippage is enabled. Works in conjunction with IsSlippageEnabled and IsLimitSlippageEnabled.
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript123 { public class SlippageOverrideExample : UserStrategyBase { public override void Initialize(BarHistory bars) { BacktestSettings.IsSlippageEnabled = true; BacktestSettings.SlippagePercentStocks = 0.1; StartIndex = _slowPer; _fast = SMA.Series(bars.Close, 20); _slow = SMA.Series(bars.Close, _slowPer); PlotIndicatorLine(_fast, WLColor.Blue); PlotIndicatorLine(_slow, WLColor.Black); } public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { if (_fast.CrossesOver(_slow, idx)) PlaceTrade(bars, TransactionType.Buy, OrderType.Market); } else { if (_fast.CrossesUnder(_slow, idx)) PlaceTrade(bars, TransactionType.Sell, OrderType.Market); } } SMA _slow; SMA _fast; int _slowPer = 50; } }
Specifies the number of ticks of slippage applied to futures Transactions when slippage is enabled. Works in conjunction with IsSlippageEnabled and IsLimitSlippageEnabled.
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript124 { public class SlippageOverrideExample : UserStrategyBase { public override void Initialize(BarHistory bars) { BacktestSettings.IsSlippageEnabled = true; BacktestSettings.SlippageTickFutures = 2; StartIndex = _slowPer; _fast = SMA.Series(bars.Close, 20); _slow = SMA.Series(bars.Close, _slowPer); PlotIndicatorLine(_fast, WLColor.Blue); PlotIndicatorLine(_slow, WLColor.Black); } public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { if (_fast.CrossesOver(_slow, idx)) PlaceTrade(bars, TransactionType.Buy, OrderType.Market); } else { if (_fast.CrossesUnder(_slow, idx)) PlaceTrade(bars, TransactionType.Sell, OrderType.Market); } } SMA _slow; SMA _fast; int _slowPer = 50; } }
By default, the benchmark Buy & Hold backtest does not use margin. Set this property to true to allow the benchmark to use the Margin Factor configured in the backtest's PositionSize.
If set to true, WealthLab applies MaximumCommission when calculating simulated commissions.
If set to true, WealthLab applies MinimumCommission when calculating simulated commissions.
If set to true, WealthLab uses U.S. Treasury yields instead of CashInterestRate when calculating simulated interest earned on cash. The Treasury maturity is specified by YieldPeriod.
If greater than zero, limits the Quantity of a Transaction based on the specified percentage of the entry bar's volume.
Specifies the U.S. Treasury maturity to use when UseUSTRateAsInterest is true.
Possible values are:
- OneMonth
- ThreeMonth
- SixMonth
- OneYear
- TwoYear
- ThreeYear
- FiveYear
- SevenYear
- TenYear
- TwentyYear
- ThirtyYear
Specifies the base currency used when MultiCurrency is enabled. The default value is "USD".
If set to true, WealthLab enables multi-currency backtest processing.
Creates and returns a copy of the BacktestSettings instance. The method persists and parses the normal BacktestSettings properties and also explicitly copies RetainNSFPositions and IntradayWeightScale.
Creates and returns a BacktestSettings instance from the persisted configuration string in s. The method also supports BacktestSettings strings saved by older WealthLab versions.
Returns a string containing the persisted BacktestSettings configuration. Advanced Strategy settings such as RetainNSFPositions and IntradayWeightScale are not included in this persisted string.