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
RSS

Navigation


Quick Search
»
Advanced Search »


FillSeriesFromFile

RSS

Syntax


public static int FillSeriesFromFile(this DataSeries Series, WealthScript ws, string FileName)
public static int FillSeriesFromFile(this DataSeries Series, WealthScript ws, string FileName, char separator, string DateTimeFormat)
public static int FillSeriesFromFile(this DataSeries Series, WealthScript ws, string FileName, char separator, string DateTimeFormat, bool exactMatch)
public static int FillSeriesFromFile(this DataSeries[] SeriesArray, WealthScript ws, string FileName, char separator, string DateTimeFormat, bool exactMatch)

public int FillSeriesFromFile(DataSeries Series, string FileName) public int FillSeriesFromFile(DataSeries Series, string FileName, char separator, string DateTimeFormat) public int FillSeriesFromFile(DataSeries Series, string FileName, char separator, string DateTimeFormat, bool exactMatch) public int FillSeriesFromFile(DataSeries[] SeriesArray, string FileName, char separator, string DateTimeFormat, bool exactMatch)

SeriesThe resulting Series name
objWealthScript obj. Pass this
Series[](optional) The resulting Series name array
FileNamePath to the file containing data series
separator(optional) Separator char used to isolate dates from the series
DateTimeFormat(optional) Custom DateTime Format String, according to this Microsoft KB article
exactMatchoptional) If true, returns the precise DateTime value - otherwise, the first bar whose DateTime is greater than or equal to the specified date

Description

This is a generic procedure (initially written by Glitch for WLD3) that will populate a Price Series with data from a file. The file should contain 1 row of data per bar. The format of each row can be:

Date (as yyyyMMdd),Value

For example, here are the first few lines of a file used in the creation of this script:

20080929,-0.714285714 
20080930,0.5 
20081001,-0.461538462 
20081002,0.876923077 

If the format of your data file differs from our example above, use an override method that provides additional control by specifying custom separator (data type char) and DateTime Format String (according to this Microsoft KB article).

Example

Below is a sample Strategy that uses the procedure. Be sure to create the series first, as is done here:

Example using C# extension methods:

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies { public class FillSeriesFromFile_Demo : WealthScript { protected override void Execute() { // Path to the data file containing external series string path = @"C:\DataSeries.txt"; // Series to fill DataSeries MySeries = new DataSeries( Bars, "MySeries" ); // Call the FillSeriesFromFile method MySeries.FillSeriesFromFile( this, path, Char.Parse(","), "yyyyMMdd" ); ChartPane MyPane = CreatePane( 30, true, true ); PlotSeries( MyPane, MySeries, Color.Red, WealthLab.LineStyle.Histogram, 2 ); } } }

Legacy syntax example:


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using Community.Components; /*** Requires installation of Community.Components Extension from www.wealth-lab.com > Extensions ***/

namespace WealthLab.Strategies { public class FillSeriesFromFile_Demo : WealthScript { protected override void Execute() { // Path to the data file containing external series string path = @"C:\DataSeries.txt"; // Series to fill DataSeries MySeries = new DataSeries( Bars, "MySeries" ); // Create an instance of class that holds the method, passing a WealthScript reference SeriesHelper sh = new SeriesHelper( this ); // Call the FillSeriesFromFile method sh.FillSeriesFromFile( MySeries, path, Char.Parse(","), "yyyyMMdd" ); ChartPane MyPane = CreatePane( 30, true, true ); PlotSeries( MyPane, MySeries, Color.Red, WealthLab.LineStyle.Histogram, 2 ); } } }

This example illustrates importing from a file which contains multiple DataSeries and creating them at once as a DataSeries array.

Before running this example, make sure you've created a file "test.txt" containing the following strings, in C:\temp:
20100301,0.5,0.9
20100302,0.3,0.6


Example using C# extension methods:


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { // Path to the data file containing external series string path = @"C:\temp\test.txt"; // Define two data series to fill DataSeries Series1 = new DataSeries( Bars, "Series1" ); DataSeries Series2 = new DataSeries( Bars, "Series2" ); // Create an array of DataSeries capable of holding 2 series DataSeries[] ds = new DataSeries[2]; ds[0] = Series1; ds[1] = Series2; // Let FillSeriesFromFile fill your series, passing the array created earlier ds.FillSeriesFromFile( this, path, Char.Parse(","), "yyyyMMdd", true ); // Plot it ChartPane MyPane = CreatePane( 20, true, true ); PlotSeries( MyPane, Series1, Color.Blue, LineStyle.Solid, 1 ); PlotSeries( MyPane, Series2, Color.Red, LineStyle.Solid, 1 ); } } }

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.