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.
|