Note:
Version 1.2.5 of the ASCII data provider contains an architectural change that brings serious performance improvements. From now on, it makes possible to work with ASCII files at the speed of binary files! If you used to export ASCII data to binary formats to speed up processing, there's no more need to do so.
Exporting to ASCII comma-separated files (CSV)
With WL6 you can export data effortlessly when required. The example below dumps security data of each symbol in the DataSet to ASCII comma-separated (CSV) files. (Modified routine 2/18/2014 to use simply use File.WriteAllLines instead of StreamWriter.)
Configure target directory:
using System;
using System.Collections.Generic;
using System.Text;
using WealthLab;
using System.IO;
public class Export2ASCII : WealthScript
{
protected override void Execute()
{
const string sep = ",";
const string fmt = "0.00########";
string dtefmt = "yyyyMMdd";
if( Bars.BarInterval > 0 )
dtefmt = "yyyyMMdd HHmm";
string path = @"C:\Data\ASCII\";
if (!Directory.Exists(path))
throw new Exception("You must create the directory " + path);
PrintStatusBar("Exporting: " + Bars.Symbol);
string file = path + Bars.Symbol + ".csv";
List datalist = new List();
for(int bar = 0; bar < Bars.Count; bar++)
{
string csv = Datebar.ToString(dtefmt) + sep
+ Openbar.ToString(fmt) + sep
+ Highbar.ToString(fmt) + sep
+ Lowbar.ToString(fmt) + sep
+ Closebar.ToString(fmt) + sep
+ Volumebar.ToString("0");
datalist.Add(csv);
}
File.WriteAllLines(file, datalist);
RestoreContext();
PrintStatusBar("Complete!");
}
}
Exporting indicators
To add custom indicators to the export file (RSI for example), modify the code as shown below:
...
// + Volumebar.ToString("0");
+ Volumebar.ToString("0") + sep
+ RSI.Series(Close, 14)bar.ToString(fmt);
...
Exporting all data by DataSet
Sometimes you might want to loop through all (or some) DataSets and export the data to CSV in bulk manner. Code in this thread will do the job:
Looping through DataSets
Getting dates formatted in a custom way
To create the Date/Time in one of the standard formats (or in a custom one), modify the code as shown below:
As you see, instead of using the
.ToShortDateString that takes the format specified in Windows Control Panel's Regional settings applet, we're getting the desired output by using .
ToString() and passing a format string:
...
csv.WriteLine( Datebar.ToString("yyyyMMdd") +
...
This instructs the program to output the date formatted as
yyyymmdd. More format examples can be found on Microsoft's site:
Standard DateTime Format Strings
Custom DateTime Format StringsExporting as WLD 3/4 native binaries (*.WL)
WL3/4 support has ended. Protected content.