Search Framework:
Strategy
Namespace: WealthLab.Backtest
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.

Strategy Properties
Author
public string Author

The WealthLab username of the Strategy's author.


Benchmark
public string Benchmark

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.

Example Code
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
            }
        }
    }
}

DataRange
public DataRange DataRange

Returns a DataRange type that was used for the Backtest.


DataSetName
public string DataSetName

Returns the name of the DataSet selected for a Portfolio Backtest.

Example Code
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
            }
        }
    }
}

FolderName
public string FolderName

Returns the name of the folder where the strategy was last saved.


GranularLimitStopScale
public HistoryScale GranularLimitStopScale

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


LibraryName
public string LibraryName

Returns the name of the assembly for a compiled strategy.


PositionSize
public PositionSize PositionSize

Returns the positing sizing method (instance of the PositionSize class) used in the backtest.


RetainNSF
public bool RetainNSF

True if the strategy should retain Positions with Not Sufficient Funds

Example Code
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
            }
        }
    }
}

RunWithPreferredValues
public bool RunWithPreferredValues

True if the strategy should be run using Preferred Values from an optimization.


SingleSymbol
public string SingleSymbol

The symbol to use for the single symbol backtest.

Example Code
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
            }
        }
    }
}

SingleSymbolMode
public bool SingleSymbolMode

True if the strategy was run in single symbol mode, otherwise false for a Portfolio Backtest.

Example Code
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
            }
        }
    }
}

StrategyData
public string StrategyData

A copy of the strategy code, rules, etc.


UpdateGranularData
public bool UpdateGranularData

True if granualar data should be updated during the backtest.

See also: GranularLimitStopScale