Before reading this post, I suggest you start by the following posts Trading Items: Data Download using .Net Scripts and Download Trading Data using the URL-Script (If you haven't done so already).
Pre-Scripts are mainly used to modify downloaded data before it is passed to the parser.
A very common example is a Pre-Script formula that loops through each line and reject those that are empty.
Here is a sample data example:
Once you specify the parser columns (Symbol, Date, Close, Open, High, Low, Volume), and start the parsing process, an error will be generated. The error will occur in the second line and it will look like "Cannot parse value '-' in column Close".
In the above case, a Pre-Script could be used to reject that line from the data.
Here is the script:
for(int i=0;i < Content.Rows.Length;i++)
string close = Content.Rows[i].Data;
if(close == "-")
Content.Rows[i].IsIgnoreLine = true;
The idea is to loop through all rows/lines and read the value of the close field (For the above data the separator is a semi-colon and the close field is located at the column number 2 - The first column number is 0).
We then check the value of the close field and if it is equal to "-", we ignore the line by setting the "IsIgnoreLine" variable of corresponding row to "true".
Note that this is a very basic example; it could be solved by checking "Continue parsing even if there are errors" in the parser form instead of creating a Pre-Script.
Pre-Scripts could be used to:
- Update the close, open, high and low prices to adjust them for splits and dividends (If there is an adjusted close field for example)
- Duplicate rows in case a row references data for several symbols or dates
- Manually create rows based on the existing data
- Fix bad ticks/data (Example: Open price is set to zero)
- Read EOD/Intraday/Tick/Custom databases data
- Automatically create custom databases and fields based on the downloaded data