Syntax
public void SimTradeFile(string TradeFileName, string DateTimeFormat)
public void SimTradeFile2(string TradeFileName, string DateTimeFormat)
Parameter Description
| TradeFileName |
The full path to the text file containing historical trades |
| DateTimeFormat |
One of standard .NET strings that specifies the DateTime format used in the trade file (see below)
|
Description
Original SimTradeFile
This is a port of sjost's
SimTradeFile 1.1 to Wealth-Lab 5. SimTradeFile is a helper method that helps you pick up a series of real (historical) trades from a text file on your disk to visualize and analyze them as if they were natively created in a Wealth-Lab 5 Strategy.
It reads a file that contains trade executions (one trade per line) and then forces Wealth-Lab's engine to take the same trades - with the help of
EnterAtPrice and
ExitAtPrice functions. Once you run the strategy, you will have access to all of the familiar analysis tools in Wealth-Lab.
Compared to the original V4 version, there are certain enhancements intended for a more flexible import:
- Data in the file can be separated by tabs, commas or dots with commas
- You can specify the Date format by passing a specific string e.e. "ddMMyy". It actually can be any date format supported by .NET. For more details, see these documents:
Standard DateTime Format Strings
Custom DateTime Format StringsYou will need a data file that contains your trade executions in a similar format:
Short;QQQQ;25-06-2009;36;25-06-2009;35.5;2000
Long;AAPL;12-05-2009;124;26-05-2009;130.4
- Trade size can be specified in the file, and it is supported using Wealth-Lab version 5.6 and up (optional parameter).
- Here, the separator char is ';' but it also can be any one of these: tab, comma, dot with comma.
- Here, the date format is dd-MM-yyyy but as stated above, it can be any supported format. Just make sure to pass a correct DateTime description string the method.
- The first line of the file can't contain a heading.
- Empty lines are ignored
- The Strategy should be executed in single symbol mode backtest (SSB), not MSB.
It's important that
both the trade data file and symbol price data is error free, or else Wealth-Lab will generate an error and may not take all of the trades. There is some basic error checking: entry and exit errors will be output to the debug window. If some of your trades isn't imported, here's a check list:
- Is your trade trying to enter above the high or below the low of bar?
- If your position isn't exited properly, check if you tried to exit below the low or above the high.
- Does the bar exist in your datasource? Refresh it if required.
- Is the bar range correct? Edit the bar if required.
- Is the symbol present in the DataSet?
- 'Index out of range' most likely indicates that the symbol requires updating its data.
- Are trades being duplicated? Ensure it's not running in a multi-symbol backest (MSB).
You can also run the chartscript by opening it and pointing to a symbol. No matter which symbol you point to you will get the same list of trades that is specified in the trade file.
Robert Sucher version
The library also contains a similar version (a.k.a. SimTradeFile2) created independently by Robert Sucher. Every bit of the description above applies to it, and the only difference is in the file format:
AAPL;12-05-2009;Buy;124
AAPL;26-05-2009;Sell;130.4
QQQQ;25-06-2009;Short;36
QQQQ;25-06-2009;Cover;35.5
As you see, each trade component - long, short, sell or cover - must be placed on its own line and is treated individually.
Example
Below is a demo Strategy that shows how to use the function.
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using Community.Components; // real trades
namespace WealthLab.Strategies
{
public class RealTradesDemo : WealthScript
{
protected override void Execute()
{
// Create an instance of the class that has the methods,
// passing WealthScript as "this"
PositionHelper ph = new PositionHelper( this );
// Original SimTradeFile:
ph.SimTradeFile(@"C:\Data\Trades.csv", @"dd-MM-yyyy");
// Try it with file containing the following lines:
//Short,QQQQ,25-06-2009,36,25-06-2009,35.5
//Long,AAPL,12-05-2009,124,26-05-2009,130.4
// Robert Sucher version:
//ph.SimTradeFile2(@"C:\Data\Trades2.txt", @"dd-MM-yyyy");
// Try it with file containing the following lines:
//AAPL;12-05-2009;Buy;124
//AAPL;26-05-2009;Sell;130.4
//QQQQ;25-06-2009;Short;36
//QQQQ;25-06-2009;Cover;35.5
}
}
}