Click here to Login









Download Trading Data using the Pre-Script

Updated on 2011-02-22





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:
MSFT;04-01-2010;12.5;12.6;12.6;12.5;2554
MSFT;03-01-2010;-;-;-;-;-
MSFT;02-01-2010;12.5;12.6;12.6;12.5;2554
MSFT;01-01-2010;12.5;12.6;12.6;12.5;2554

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[2];
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.

Some Examples

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












no comments (Log in)

QuantShare Blog
QuantShare
Search Posts




QuantShare
Recent Posts

Lock, Link and Undock your Charts
Posted 531 days ago

QuantShare
Previous Posts

QS Trading Software: Global Script
Posted 3307 days ago


More Posts

Back







QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright 2019 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.