Wealth-Lab Wiki

API ChartStyles Community Components Community Indicators IndexDefinitions Knowledge Base Misc Optimizers Pending Deletion PosSizers Providers Standard Indicators TASC Traders Tips TASCIndicators Tutorial Videos Visualizers


Quick Search
Advanced Search »

FAQ | Position Sizing, Extensions, Miscellaneous


PosSizers (position sizing)

I'm using 100% Equity position sizing and strategy doesn't seem to use all capital and/or there are trades not included due to insufficient capital.

Also, when using 10% Equity on a portfolio of 10 stocks, same rules apply. The reason is that when Wealth-Lab determines the number of shares for an order, it does so with regard to the so called "basis price". For the whys and wherefores of it and specifically how this can cause skipped trades with trade sizes near 100% equity, refer to the User Guide: Strategy Window > Backtesting Strategies > 100% of Equity Sizing.

Finally, make sure that "Limit a Position's Quantity to a Percentage of the Bar's Volume" is unchecked in Wealth-Lab's Preferences dialog.

Workaround #1: Position Options PosSizer includes a "Skipped trade solution" that helps overcome it by adjusting the basis price.

Workaround #2: For AtMarket orders, by overloading the market order with a limit order at the opening price, you can get all the trades if you run without commissions. With commissions, bump up Margin Factor a bit (e.g. 1.01) to ensure you get all the trades. Add this method to your Strategy class:

/* Add this BuyAtMarket method and nothing else needs to be changed */
      // It uses a limit order that executes at the opening price so that the basis price is the same as the execution price
      Position BuyAtMarket(int n, string sigName = "")
         if (n >= Bars.Count)
            return base.BuyAtMarket(n, sigName);   // create market order alert
            return BuyAtLimit(n, Open[n], sigName);

When I run a strategy in a Raw Profit mode, a warning message tells me that some trades were dropped because of insufficient funds. Why?

It is possible in Raw Profit mode when a) Fixed Dollar sizing is selected and b) the selected position size is not enough to purchase even one share of the instrument. It can happen with with higher-priced instruments such as indices. Consider this example: your position size is $1,000 Fixed Dollar, and at the time of entry the security's price exceeds the position size e.g. is $1,100. There are two options: switch to Fixed Shares or increase the Fixed Dollar position size.

How do I implement volatility position sizing?

Position sizing based on volatility suggests to keep a wider stop when the market has a higher volatility while preserving your maximum per trade loss, effectively instructing to buy less shares during volatile periods, and more shares during calmer periods.

A simple and effective solution that requires no coding: the Percent Volatility PosSizer. As an alternative, to determine the stop based on volatility (for instance, as a multple of the ATR unit), pass it as RiskStopLevel before taking the Position, and use Max Percent Risk sizing.

Having read about "Operational difference between the Strategy Monitor and Backtester" in the User Guide, I wonder if it's possible to use percent of capital position sizing in SM?

In live trading, you only need to determine what that % of Equity once per day when you enter your trades. That will be some cash value, like $9,587. For the S. Monitor, then, you use Raw Profit mode and enter that value for the dollar size. The next day, you recalculate the size based on your account's equity value and change the Raw Profit dollar size again, and so on.

How do I limit the maximum number of positions across the portfolio?

You need a PosSizer that can limit the number of open positions across the portfolio: Position Options.

Is it possible to exit trades when portfolio drawdown reaches -X% (for example)??

No. PosSizers will not enter or exit trades, they can only affect the position size of the next trade, or reject it completely. Consequently, if you stop trading after reaching drawdown of some magnitude, with no positions there will be nothing to raise the equity curve back.

How to size a Position based on a DataSeries value? How to limit the number of entered positions based on a DataSeries value?

The most straightforward way is to pass that value with the Position's Priority or (better) Tag properties. Check this forum thread for some helpful code snippets.

Is it possible to use PrintDebug in a PosSizer?

Just not the built-in PrintDebug. However, to use the Output window of Visual Studio or SharpDevelop, you need to do the following:

  1. Hit Ctrl-W, O to open the Output window (VS 2008 shortcut; Ctrl-Alt-O in SharpDevelop).
  2. Call Trace.WriteLine in your PosSizer:

System.Diagnostics.Trace.WriteLine( whatever_you_wanted_to_send_to_PrintDebug );

Is it possible to optimize a PosSizer?

Directly, no. However, you can pass on the optimizable value(s) from your Strategy to your custom PosSizer using the Position.Tag property.

How to pass a value from Strategy to PosSizer for Alert sizing?


You're using currentPos.Tag to size positions in a PosSizer which works only if currentPos is not null i.e. not for Alerts.


It's possible to assign any value to the Bars object using the Tag property when sizing for an Alert and read it back in your PosSizer:

if( bar == Bars.Count-1 ) )
   Bars.Tag = some_double_value;

For a complete code snippet, refer to the Bars.Tag example in the Wealth-Lab QuickRef.

No programming required:

Starting from version 2011.11, the Position Options PosSizer supports passing a double value via Position.Tag or SetShareSize to easily backtest a strategy-driven, flexible percent-equity or Max % Risk approach.

Why checking for EntryBar/ExitBar in portfolio simulations may produce unexpected results in PosSizers and Performance Visualizers?

Reason: because the different historical DataSets aren't synchronized when backtesting.

Solution: check for the date with EntryDate/ExitDate rather than the bar number:

// Fails:
//if (Positions[n].EntryBar == bar + 1)
// Workaround:
if(Positions[n].EntryDate == bars.Date[bar + 1].Date)

Why accessing an EquityCurve(CashCurve) value in multi-symbol portfolio simulations may produce unexpected results in PosSizers and Performance Visualizers?

Reason: because the different historical DataSets aren't synchronized when backtesting.

Solution: in a multi-symbol backtest, it's advised to use the ConvertDateToBar method of the EquityCurve or CashCurve DataSeries to get a correct bar. For example, here's how to determine the equity curve value at the beginning of a month using ConvertDateToBar:

double MonthStartEquity = EquityCurve[0];
DateTime b = bars.Date[bar];
DateTime tmp = new DateTime(b.Year, b.Month, 1);
MonthStartEquity = EquityCurve[EquityCurve.ConvertDateToBar(tmp, false)];


I can't download an Extension: the site says Wealth-Lab extensions are available only to Wealth-Lab Version 6 customers.

Wealth-Lab Extensions are not available during free trials. Extensions are premium content available to our registered customers, for free. They are not a part of Wealth-Lab Developer/Pro (excluding those already shipped with the installation and available without downloading), they're free, and are not subject to "try before you buy". No downloadable extension is an inherent part of the application without which it would cease to function.

I can't see any open source in the Wealth-Lab Wiki?

Open source project code is available to registered customers of Wealth-Lab Developer/Pro, for free, and can be downloaded by clicking on "Attachments" of a project's home page. WLD/WLP customers who can't see "Attachments" - please enter a new support ticket at wealth-lab.com. Note: source code is not available to trial users.

Extension installed in Wealth-Lab Developer doesn't show up after restarting application.

This can happen when you have both x86 and x64 versions of Wealth-Lab Developer installed on the same computer. Installing an Extension in x86 version (for example), closing it and starting x64 version makes believe the Extension is gone. Because their executable/DLL files are installed into separate locations, Extensions should be installed separately for x86 and x64 versions of Wealth-Lab Developer (note: some Extensions can be incompatible with x64 version).

Data providers only: another possible reason is missing Market Manager - a required component of many data providers. To get it back, reinstall any provider using it from the Extensions section - ASCII, for example - and restart Wealth-Lab.

When installing extensions obtained by email or file download from 3rd party sources (be careful!), such files are automatically marked by Windows as "insecure" (all versions starting from Windows 7). After dropping such DLL file into Wealth-Lab's program folder, it will not be loaded. Close Wealth-Lab and clear the "File downloaded from the internet" flag in File Properties as suggested in this article: What Causes the "File Downloaded from the Internet" Warning and How Can I Easily Remove It?

I'm getting an "access denied" error while building my extension in Visual Studio or SharpDevelop.

If the error message reads like this, you have Windows Vista, 7 or greater and should start Visual Studio or SharpDevelop with admin privileges explicitly, by right-clicking the shortcut and selecting "Run as admin":

Error Unable to copy file "MyExtension.dll" to "..\Program Files\MS123\Wealth-Lab Developer 6\...". Access to the path is denied.

Can not compile my library after installing Wealth-Lab 6.9. What's wrong?

Select .NET 4.5 or 4.6 Framework as target platform.


I have a library of compiled Strategies. When I open some of them, all are the same or not the one I picked.

If opening differently named Strategies result in opening the same Strategy, and/or not the one you want, this is a common symptom of one (or several) of your Strategies not having a unique GUID. You should correct the code so that the GUID of each Strategy in your class library is unique. For more details, see this article.

I successfully created a library of compiled Strategies but it crashes Wealth-Lab. Restart or reinstallation doesn't help.

When implementing the interface, you left one or more instance of method returning NotImplementedException.

            //INCORRECT !
            throw new NotImplementedException();

These exceptions will cause a startup crash. Uninstallation will not help as it does not remove custom files (but the program's own). You could either delete the DLL file or simply rewrite the code to return whatever types are expected, making sure that no "throw new NotImplementedException();" line remains.


I created an indicator library, but it doesn't show up in Wealth-Lab 6

Verify that...

  • for an Indicator, you have correctly implemented the IndicatorHelper
  • placed the resulting DLL in Wealth-Lab's main folder
  • targeted the right framework version. To be recognized by Wealth-Lab 6.4, .NET 4.0 can be selected. For version 6.3 and earlier, libraries must be targeting .NET 2.0 or 3.5 (by default, Visual Studio 2010 targets .NET 4.0 which is incompatible with WL 6.3 - this can be changed in your project's properties, and it should be recompiled)
  • the target CPU is set to Any (and not to e.g. 32 bit)
  • restarted Wealth-Lab after placing the DLL(s), if it was running.

I compiled TASCIndicators from source files but having trouble installing it.


When trying to update TASCIndicators (or any other open source Extension) to get some new functionality (e.g. an indicator), you are building the source into a DLL and replacing the old one, but Wealth-Lab's built-in compiler won't recognize the new indicator, producing an error message that looks as follows:

error CS1704 @ (0.0): An assembly with the same simple name "TASCIndicators, Version=, Culture=neutral, PublicKeyToken=nul 

In addition, if you were trying to update an Indicator Library, a common symptom is to see two related Indicator groups (folders) in the Indicator List window.


This is the result of copying the assembly (DLL) in a wrong way, for example:

  • If the new file has a name different from the original library (e.g. you are copying TASCIndicators.dll as TASCIndicators1.dll to the Wealth-Lab main program directory.
  • If you renamed the original file for backup purposes but preserved the .dll extension (e.g. you've copied the new file named TASCIndicators.dll, renaming the old file as TASCIndicators.Copy.dll).

In both cases, you've got two conflicting files named differently. When starting up, Wealth-Lab scans for DLLs in its main program folder and if an assembly was recognized as implementing a certain interface (e.g. an indicator library), it will be loaded without version check, and its file will be consequently locked up.

Backing up an existing library is a good idea, but you should do so by renaming it in a way that effectively hides it from Wealth-Lab -- a proper file name would be, for instance, TASCIndicators.dll.bak.


One of the Performance Visualizer tabs is missing.

Make sure the checkbox for the Visualizer is checked under Tools > Preferences > Performance Visualizers. If using a saved workspace, then it's possible that the window that you saved with the Workspace was created when the Visualizer was not enabled. Open that workspace, close the window, open that Strategy again, and re-save the workspace.

Why there's a difference in the value in profit on "By Period" vs. "Trades" tabs?

"By Period" returns are the difference in the values of the equity curve from one period to the next. That's not the same as trade profit. More details can be found here.

Oddities on the "By Period" tab

On the "By Period" tab, there are oddities looking like a bug: multiple months have duplicate entries, the order of months is incorrect etc.

Error in your data like an out-of-sequence bar. You need to find the bad symbol using the Data Tool and reload its data.

Is there any way to add a column to the Trades visualizer and write data to it?

To the built-in performance visualizer, no.

To your own custom performance visualizer, yes. For example you can download Community.Visualizers demo source code and modify the PVTrades2 class that represents the Trades+ visualizer. In short, adding a column would take the following:

  1. Add a column to the ListView (by defining a ColumnHeader) of the control.
  2. Specify the type of data (i.e. double) for the purposes of sorting (notice ListViewSortManager in the PVTrades2 constructor).
  3. GenerateOutput is used for copying to clipboard, so you should skip this method for now.
  4. Now, in CreateVisualization method body you will need to calculate your performance metric and use AddSubItem to push it to the ListView.

Why checking for EntryBar/ExitBar in portfolio simulations might fail In PosSizers and Performance Visualizers?

Answered above (PosSizers section).

I get strange results in backtesting that are hard to explain...

See below for explanations:

Data and Broker providers

You must be a verified Wealth-Lab Developer/Pro 6 customer to view this page. Free trial users can not access this content.


Is it possible to calculate correlation?

Is portfolio rebalancing possible?

Not directly, but here are a few pointers: forum thread.

Is there a way to suppress the chart title with the symbol name and the rectangular box around it?

To put it simply, you can hide it by opening the Preferences dialog and setting the font size of the "Symbol & Co. Name" to 1.

Is there a way to profile Wealth-Lab 6 Strategies i.e. measure application/script performance?

Yes. This procedure helps find code bottlenecks. Please refer to this discussion: Wealth-Lab strategy performance profiling

Is it possible to do multi-currency backtests with Wealth-Lab?

Wealth-Lab is single-currency focused, but some pointers worth taking a look can be found in this discussion.

Is it possible to use Wealth-Lab for futures spread trading?

You might find some pointers here.

Before upgrading to v6.2 I used an older version, now am experiencing differences with same code working with AtStop/AtLimit orders?

In 6.2, there were changes made that prevent skipping otherwise valid AtStop/AtLimit orders taken at bar's extremes that could happen in preceding versions. By default, Wealth-Lab adjusts stop/limit trigger prices to a "tick" value for stocks as well as futures. The tick value depends on the Pricing Decimal Places (configured in Wealth-Lab's Preferences > Advanced Options). Sometimes this adjustment may cause a stop/limit order to fail due to precision issues. Versions prior to 6.2 assumed a 2-decimal "tick value" for stocks which could cause skipped AtLimit/AtStop orders.

Version 6.2 and higher provides more precision because the tick value will now use the number of Pricing Decimal Places configured (Preferences dialog). For instance, the tick is 0.001 if you set the number of decimals to 3. To sum it up, if you enter 3 Pricing Decimal Places in 6.2, stocks will be displayed and traded at 3 decimals. To completely ignore tick value adjustments, use the new option (from 6.2) called "Turn off limit/stop order rounding entirely" (Preferences > Backtest Settings). By enabling this option, you tell Wealth-Lab not to adjust stop/limit prices to a stock's tick value, instead executing the orders at full decimal precision.

Note: a correct comparison between the backtests created in 6.2 and earlier versions requires the number of Pricing Decimal Places to be set at 2 in both versions of Wealth-Lab.

Important Disclaimer: The information provided by Wealth-Lab is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.  The owner of Wealth-Lab.com assumes no liability resulting from the use of the material contained herein for investment purposes. By using this web site, you agree to the terms of this disclaimer and our Terms of Use.

Used under license from FMR Corp. Copyright 2008 FMR Corp. All rights reserved.

ScrewTurn Wiki. Some of the icons created by FamFamFam.