Click here to Login




How to create a trading indicator that uses stock news

Updated on 2010-06-29





If you haven't yet read last week's post, please take a look at How to create your own technical analysis indicators.

In this post, we will talk about a single function in the indicator tool. A function that is important and can be used to accomplish many things. This function name is "GetCustomDatabaseData" and its purpose is to retrieve historical and intraday data from custom databases.

Custom databases are historical or intraday databases and can store any kind of data for any ticker symbol. You can create as many custom databases as you want and each database can contain any number of text or numeric fields. Example: Fundamental database, news database, short selling database.
The "GetCustomDatabaseData" function as we already said gets databases data for the current symbol or for any other symbol.

To get data for the current stock (Example: The stock that is displayed in the chart that uses the indicator):
VectorCustom vect = cFunctions.GetCustomDatabaseData("yahoo_news", "title");
To get data for any other stock: ("A" is the ticker symbol of Agilent Technologies Inc.)
VectorCustom vect = cFunctions.GetCustomDatabaseData("yahoo_news", "title", "A");

The retrieved data from the custom database is aligned with the specified symbol historical data. This means that if you are using a daily timeframe and a news database, for any trading bar you can get all news titles that occurred during a specific trading day. This also means that if a news title occurred on a day that comes after or before the last or the first historical quote's date for a given stock; you will not be able to access this news data using the "GetCustomDatabaseData" function.

Here is an example that creates an indicator that calculates the number of news per day for a given security. This trading indicator uses stock news data that were downloaded using the following trading object: Yahoo News.
This implementation is equivalent to the vector-based indicator "GetDataCount" which can be found in the QuantShare Trading Software.

C# Code:
VectorCustom vect = cFunctions.GetCustomDatabaseData("yahoo_news", "title");
for(int i=0;i<vect.Length;i++)
{
    result[i] = vect[i].Length;
}


Here is how it works:
The above code gets the vector that contains database data for a specific stock, currency or ETF, loops through all bars and gets the number of news titles. It finally assigns that number, for each trading day, to the "result" vector.

Instead of using the "Length" method to calculate the number of news titles, you could have used the "GetValue" or "[index]" function to read and parse the content of the database.
Example:
object obj = vect[i][0];

This line gets the first element of the database for the bar number "i". The returned value is of type object. You can cast it to numeric or string depending on the field content type.
For the news database you can do the following:
string title = (string)vect[i][0];
Or
string title = vect[i][0].ToString();

For a numeric database's field, you may use:
double value = (double)vect[i][0];


Here are some nice trading indicators that use "GetCustomDatabaseData" function:
News Sentiment Indicator creates a sentiment index by subtracting the number of positive words by the number of negative words. It works with any database and can be easily customized by adding the positive and negative words.
The News parser function returns the number of items that contain specific words.
The Short selling indicator measures long and short volume activity and determines whether the short volume is higher than the long volume or not. It uses historical short selling data that are downloaded using Short Selling Data.











no comments (Log in)

QuantShare Blog
QuantShare
Search Posts




QuantShare
Recent Posts

Create Graphs using the Grid Tool
Posted 1407 days ago

Profile Graphs
Posted 1512 days ago

QuantShare
Previous Posts

Correlation of market indicators
Posted 5266 days ago

Backtesting Process
Posted 5280 days ago

Trading software new features
Posted 5286 days ago

Optimization of a trading system
Posted 5301 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 © 2024 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.