Accessing non-price info from a database
Author: sf631
Creation Date: 1/31/2014 9:25 PM
profile picture

sf631

#1
I have a database table which contains news headlines (short text strings) that I'd like to be able to display on a chart with AnnotateBar(). I am able to connect to the database but can't understand how that helps me if the database contains anything other than OHLCV info (it's got timestamp but otherwise just text fields, I already have the OHLCV from other data providers.

So, is there a way that the database provider is useful to me, or do I need to just somehow connect directly to the database from C# code (connection string etc...)?

I had thought there was some sort of new functionality released in 6.1 that was to help with custom data types but I struggled to find any clear documentation of what that was - or if it's relevant to my question

Thanks
profile picture

sf631

#2
OK, partially answered my own question with the "NamedSeries" option in the static provider. It didn't complain when I added a string variable to it, but I'm not getting anything out of it and don't know exactly how to verify whether it's a failure to get data into the NamedSeries (e.g., if it only accepts numerical data) or a failure to get data out of the named series (misuse of FindNamedSeries)

CODE:
Please log in to see this code.


and then

CODE:
Please log in to see this code.


profile picture

Eugene

#3
QUOTE:
I have a database table which contains news headlines (short text strings) that I'd like to be able to display on a chart with AnnotateBar().

Let me start by saying that is a task for a fundamental provider, making the news items accessible and plottable like usual fundamental items. We've developed a couple of news providers that download news items from web/RSS: Google News provider, Reuters News provider. This way of handling news items is more elegant than using AnnotateBar() to plot the strings but requires some development effort. Fortunately, we've got some sample C# code of a fundamental provider to help you get going:

Home - MS123 Providers

Taking my idea further, you can even apply text sentiment analysis to your news items using AlchemyAPI IBM Natural Language Understanding.

QUOTE:
OK, partially answered my own question with the "NamedSeries" option in the static provider. It didn't complain when I added a string variable to it, but I'm not getting anything out of it

Incorrect. Any DataSeries (including NamedSeries) can only hold values of type double. There's no place for strings there.

QUOTE:
So, is there a way that the database provider is useful to me, or do I need to just somehow connect directly to the database from C# code (connection string etc...)?

No, the Database provider is not useful for this. (This closely related thread may have more explanations: Database fundamental provider request). If the task of building a new fundamental provider seems too complicated for you, then you can:

1. Connect to the database programmatically in a WealthScript Strategy (or come up with a class library to handle this part, allowing to reuse the code in different Strategies easily). There are countless examples on the net.
2. Create a new class (e.g. NewsItem) with the timestamp and textual value of a news item and a new collection for storing them e.g. (a Dictionary or List<NewsItem>)
3. Grab the data, parse, fill up your collection by creating new NewsItems and adding them to the collection
4. Finally, loop by the collection and plot the items using AnnotateBar etc.
profile picture

sf631

#4
Thanks very much Eugene - that's a huge help. I'll try the NewsItem class approach (rather than the Fundamental Provider - that's overkill for my needs).

I was hopeful that I could get into a DataSeries so I could call with the same [bar] index as anything else in the loop, but understand why I can't. I suppose I'll need the NewsItem class to be indexed by date and access it with MyNewsItem[Bars.Date] or similar.
profile picture

Eugene

#5
Right. And for plotting with AnnotateBar, pass your NewsItem.DateTime to the indispensable DateTimeToBar method.
profile picture

sf631

#6
Will do, thanks.
profile picture

sf631

#7
OK, I've built a DLL that contains connection strings to my database and methods to access a list of NewsItems for a given ticker symbol (much as you described above, and verified that it works properly from a windows form app.

I'm able to add the reference to the WL strategy, and able to compile with the "using" statement, so I think the reference is working. I'm not however able to access any of the methods or classes in the DLL. Is it still true that WLP is based on .NET 2.0? If so, do I need to build the dll specifically for that framework?

profile picture

Eugene

#8
WLP is based on .NET 4.0 since 6.4. You didn't indicate which version you're running but anything above that is good in this context.

Not sure how you came to this conclusion, but being not "able to access any of the methods or classes in the DLL" is a suboptimal problem description. Mind reading is at least counterproductive. Exactly how did you determine that? Maybe there's a compiler error message (full text or MSDN id)? Or you declared a method as private?

At any rate, this FAQ on Extensions contains some food for thought too: "A library compiled for .NET 4.0 doesn't show up in Wealth-Lab 6" and "I created an indicator library, but it doesn't show up in Wealth-Lab 6".
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).