Parent: Object
The Strategy class holds the strategy code and other metadata information about the strategy. The Backtester class will have an instance of the Strategy being tested, and it may be useful to access some Strategy properties, for example, to ensure that the intended PositionSize is selected or to find the Benchmark symbol.
%Warning!%
Do not modify a Strategy's Properties in Strategy code. Doing so may cause your computer to overheat and the WealthLab police may knock on your door.
The WealthLab username of the Strategy's author.
The symbol to use for the comparison benchmark backtest, which is a buy & hold run that is displayed side by side with the backtest results for the Strategy.
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript123 { public class MyStrategy : UserStrategyBase { public override void Initialize(BarHistory bars) { string bm = Backtester.Strategy.Benchmark; DrawHeaderText("Benchmark is " + bm, WLColor.Red, 14); } public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } } } }
Returns a DataRange type that was used for the Backtest.
Returns the name of the DataSet selected for a Portfolio Backtest.
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript123 { public class MyStrategy : UserStrategyBase { public override void Initialize(BarHistory bars) { if (Backtester.Strategy.SingleSymbolMode) DrawHeaderText("Strategy was run in Single Symbol Mode on " + Backtester.Strategy.SingleSymbol, WLColor.Red, 14); else DrawHeaderText("A Portfolio Backtest was run on " + Backtester.Strategy.DataSetName, WLColor.Red, 14); } public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } } } }
Returns the name of the folder where the strategy was last saved.
Returns the intraday scale if a granular stop/limit processing should be performed for a backtest. If HistoryScale returns HistoryScale.Daily, then granular processing is disabled.
See also: UpdateGranularData
Returns the name of the assembly for a compiled strategy.
Returns the positing sizing method (instance of the PositionSize class) used in the backtest.
True if the strategy should retain Positions with Not Sufficient Funds
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript123 { public class MyStrategy : UserStrategyBase { public override void Initialize(BarHistory bars) { DrawHeaderText("Retain NSF is " + Backtester.Strategy.RetainNSF, WLColor.Red, 14); } public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } } } }
True if the strategy should be run using Preferred Values from an optimization.
The symbol to use for the single symbol backtest.
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript123 { public class MyStrategy : UserStrategyBase { public override void Initialize(BarHistory bars) { if (Backtester.Strategy.SingleSymbolMode) DrawHeaderText("Strategy was run in Single Symbol Mode on " + Backtester.Strategy.SingleSymbol, WLColor.Red, 14); else DrawHeaderText("A Portfolio Backtest was run on " + Backtester.Strategy.DataSetName, WLColor.Red, 14); } public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } } } }
True if the strategy was run in single symbol mode, otherwise false for a Portfolio Backtest.
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript123 { public class MyStrategy : UserStrategyBase { public override void Initialize(BarHistory bars) { if (Backtester.Strategy.SingleSymbolMode) DrawHeaderText("Strategy was run in Single Symbol Mode on " + Backtester.Strategy.SingleSymbol, WLColor.Red, 14); else DrawHeaderText("A Portfolio Backtest was run on " + Backtester.Strategy.DataSetName, WLColor.Red, 14); } public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } } } }
A copy of the strategy code, rules, etc.
True if granualar data should be updated during the backtest.
See also: GranularLimitStopScale