Do any of you have a good script or method to automate the exporting of intraday data (e.g., 1 minute, 5 minute, etc.) from a group of symbols from Tradestation? I've been doing it manually via the "View Data Window" option in Tradestation and it takes forever to select and download each symbol.
Below is a script that I have been working on. I attach this script as an indicator in the Tradestation Scanner and run it, but it doesn't output results in the same way as the "View Data Window" option does. For example, here is a sample of the results via the "View Data Window" (these work perfectly in Builder):
"Date","Time","Open","High","Low","Close","Up","Down"
06/26/2014,09:51,28.65,29.50,28.65,29.05,3472983,233903
06/26/2014,09:52,29.03,29.69,28.71,29.14,873586,783021
06/26/2014,09:53,29.16,29.48,29.12,29.33,514665,499585
But, here are the results using the script I've been working on (these don't work in Builder):
"Date","Time","Open","High","Low","Close","Up","Down","Symbol"
06/26/2014,0951,28.65,29.50,28.65,29.05,3706886,0,GPRO
06/26/2014,0952,29.03,29.69,28.71,29.14,1656607,0,GPRO
06/26/2014,0953,29.16,29.48,29.12,29.33,1014250,0,GPRO
Apparently, up-tick and down-tick volumes are combined because they are "not
accessible in RadarScreen or the Scanner", so I need a work-a-round to
separate them. I have noticed, per Mike's suggestion ...
http://www.adaptrade.com/Builder/Builderfaq.htm#Q4, that combining up-tick and
down-tick volume causes problems when getting Tradestation strategy
results to match Builder strategy results, so I always end up unchecking "Set volume to sum of up-tick and down-tick volumes".
Also, I need to place a colon between the hour and minute in order for Builder to recognize the time field.
============ begin script ============
Inputs:
OutFilePath("C:\TradeStation_Data\"),
OutFileBaseName(""),
OutFileType(".txt") ;
Variables:
OutFile(""),
Interval("");
Once begin
// Ref:
https://community.tradestation.com/Discussions/Topic.aspx?Topic_ID=103857&PAGE=1򠕫 // Define the Interval string which is the bar interval and bar type to be used in the output file name.
Switch(BarType) begin
Case 0: Interval = NumToStr( BarInterval, 0 ) + "tick" ;
Case 1: Interval = NumToStr( BarInterval, 0 ) + "minute" ;
Case 2: Interval = "daily" ;
Case 3: Interval = "weekly" ;
Case 4: Interval = "monthly" ;
Default: RaiseRunTimeError("BarType must be tick, intraday, daily, weekly or monthly");
end ;
// Create the output file name as the file path plus base name plus the symbol plus the interval plus first date to the last date plus the file type extension.
// OutFile = OutFilePath + OutFileBaseName + Symbol + "_" + Interval + " (" + Symbol + ")" + OutFileType;
OutFile = OutFilePath + OutFileBaseName + Symbol + "_" + Interval + OutFileType;
{
DateString(""),
TimeString(""),
LastCalcDateStr(""),
PathString(""),
NumDecimals(0);
DateString = ELDateToString(Date);
TimeString = Numtostr(Time, 0);
ELDateToString(Date) + " to " + FormatDate("ddd MMM dd yy", LastCalcDate)
NumToStr(LastCalcDate, 0 )
FormatDate("ddd MMM dd yy", dDateTime ));
NumToStr( Date, 0 )
}
end ;
// Print out column titles for the first bar on the chart for a column separated value (.csv) file.
// Note that this will repeat for each symbol specified in the scanner. Note that a FileAppend
// command must be used to allow us to use a variable output file name - this does NOT work for
// a Print command.
// this is the original line ... i changed it from volume to uptick and downtick
// ref:
https://community.tradestation.com/Discussions/Topic.aspx?Topic_ID=103857// ref:
https://community.tradestation.com/Discussions/Topic.aspx?Topic_ID=112074#572433// * Cannot access up ticks or down ticks in RadarScreen or the Scanner. For both RadarScreen and the Scanner, the Reserved Words UpTicks, Ticks, and Volume all return the TOTAL volume associated with a bar. DownTicks returns zero( 0 ).
// if CurrentBar = 1 then
// FileAppend(OutFile, Doublequote + "Date" + Doublequote + "," + Doublequote + "Time" + Doublequote + "," + Doublequote + "Open" + Doublequote + "," + Doublequote + "High" + Doublequote + "," + Doublequote + "Low" + Doublequote + "," + Doublequote + "Close" + Doublequote + "," + Doublequote + "Volume" + Doublequote + "," + Doublequote + "OI" + Doublequote + "," + Doublequote + "Symbol" + Doublequote + NewLine );
// FileAppend(OutFile, FormatDate("MM/dd/yyyy", ElDateToDateTime(Date)) + "," + FormatTime("hhmm", ElTimeToDateTime(Time)) + "," + numtostr(Open, 2) + "," + numtostr(High, 2) + "," + numtostr(Low, 2) + "," + numtostr(Close, 2) + "," + numtostr(Volume, 0) + "," + numtostr(Openint, 0) + "," + Symbol + newline );
//
// ref:
https://community.tradestation.com/Discussions/Topic.aspx?Topic_ID=99195#566162// _ComputerDateTimeStr(ElTimeToDateTime(Time))
if CurrentBar = 1 then
FileAppend(OutFile, Doublequote + "Date" + Doublequote + "," + Doublequote + "Time" + Doublequote + "," + Doublequote + "Open" + Doublequote + "," + Doublequote + "High" + Doublequote + "," + Doublequote + "Low" + Doublequote + "," + Doublequote + "Close" + Doublequote + "," + Doublequote + "Up" + Doublequote + "," + Doublequote + "Down" + Doublequote + "," + Doublequote + "Symbol" + Doublequote + NewLine );
// Print out for each price bar the symbol, date, time, open, high, low and close
//
https://community.tradestation.com/Discussions/Topic.aspx?Topic_ID=93619#470029 ... how to add colon to ELTime functions ... requires custom code
FileAppend(OutFile, FormatDate("MM/dd/yyyy", ElDateToDateTime(Date)) + "," + FormatTime("hhmm", ElTimeToDateTime(Time)) + "," + numtostr(Open, 2) + "," + numtostr(High, 2) + "," + numtostr(Low, 2) + "," + numtostr(Close, 2) + "," + numtostr(Upticks, 0) + "," + numtostr(Downticks, 0) + "," + Symbol + newline );
// Insert a "dummy" plot statement which is required for a Scanner indicator. Does nothing
// except provide a plot value which is required by the Scanner.
if LastBarOnChart then
Plot1( 999 ) ;
============ end script ============