PDA

View Full Version : NT7 Strategy: ExportData


MXASJ
02-20-2010, 08:56 PM
Attached a strategy that exports csv text files in the format DateTime,Open,High,Low,Close,Volume with a few options to change the output data types and file destinations via the Strategy dialog box (ie you don't have to go into the code to change stuff).

I do a lot of offline analysis and this is handy for that. DateTime output format is currently limited to POSIX (I use it with R), but if anyone wants to have a go at changing the output DateTime options to an enum and manipulate the DateTime strings it might be more useful.

Feel free to make it better!

bukkan
02-20-2010, 09:41 PM
thanks MXAJX,
btw, have you played with base.MarketData

seems lot of functions there, but no one seems exploited it.

MXASJ
02-21-2010, 05:00 AM
ver 3.01 deletes the Print statements I was using for debugging and changes an if/if chain to an if/else to save a bit of processor power. Sorry I should have cleaned it up before posting earlier.

MXASJ
02-22-2010, 02:54 AM
It was suggested I use the OnStartUp() method and move some of the code out of OnBarUpdate(). The key sections are below:


protected override void Initialize()/////////////////////////////////////////////////////////////////////////////////////////////////////////
{
CalculateOnBarClose = true;

}

protected override void OnStartUp()/////////////////////////////////////////////////////////////////////////////////////////////////////////
{
string dest = path+filename;
string defname = path + @"\" +Instrument.FullName+"_"+BarsPeriod.Value+"_"+BarsPeriod.Id+".txt";
defname = defname.Replace(' ','_'); // Replaces non-ISO file characters in Futures names
defname = defname.Replace('-','_'); // Replaces non-ISO file characters in Futures names

// If file at 'path' doesn't exist it will create the file. If it does exist it will append the file.

if (useDefaultFilename == false)
{
sw = File.AppendText(dest);
}
else
{
sw = File.AppendText(defname);
}
}

protected override void OnBarUpdate()///////////////////////////////////////////////////////////////////////////////////////////////////////
{

string sep = DataSeparator.ToString();// Cast required so the Date/Time separator and normal data separator are the same

// This is the output of all lines. The output format is: DateTime Open High Low Close Volume
string data = (Time[0] + sep + Open[0] + sep + High[0] + sep + Low[0] + sep + Close[0] + sep + Volume[0]);

if (splitDateTime == true)
{//Replace the space in DateTime with the DataSeparator
data = data.Replace(' ',DataSeparator);
}

sw.WriteLine(data);

}

protected override void OnTermination()//////////////////////////////////////////////////////////////////////////////////////////////////////
{
sw.Close();
}


This compiles and works fine, but I'd like to ask if this is the right use for OnStartUp(). Not much documentation on that yet ;).

Thanks

Ralph
02-22-2010, 04:30 AM
It is correctly used. In addition I would move the following code line to OnStartUp():

string sep = DataSeparator.ToString();//

MXASJ
02-22-2010, 07:56 AM
Thanks! Better code attached. v3.10.