Defining classes containing member fields of DataSeries
Author: superticker
Creation Date: 2/28/2015 10:54 PM
profile picture

superticker

#1
Could someone please point me to a class definition example that defines a private DataSeries that's referenced by two member functions? I'm having trouble with references to my private DataSeries, but if you can point me to an example, I'm sure I can figure it out. Some of my own code is given below.

Also, PrintDebug() fails within the class definition. Saying WealthScript.PrintDebug() doesn't help either since PrintDebug() isn't a static member. (Maybe it should be.) So how do I do a PrintDebug or Console.WriteLine() inside a class?

CODE:
Please log in to see this code.
profile picture

Eugene

#2
QUOTE:
So how do I do a PrintDebug or Console.WriteLine() inside a class?

Why reinvent the wheel and what's the problem calling PrintDebug normally i.e. from a Strategy class derived from WealthScript? You could define the Decorrelate DataSeries the usual way, pass an instance of Contrast, and debug them one by one.

QUOTE:
Could someone please point me to a class definition example that defines a private DataSeries that's referenced by two member functions?

If you can't find it among hundreds of examples in the open source code of Community Indicators and TASCIndicators, maybe there's a different way to do that something? For example, like I already told in ticket 25024, accessing external symbol's data in DataSeries isn't a trivial task.
profile picture

superticker

#3
The run-time error occurs in my Contrast class (derived from the DataSeries class), not the calling Strategy class. So how do I peek at something in my Contrast class? Are you saying PrintDebug() can't work? If so, how do I get Console.WriteLine() to work? Moreover, how do developers debug private class run-time errors if they can't sample their variables? (Certainly, I'm not the first developer to debug a class.)

I need an example where the constructor creates a DataSeries internally, which has intermediate calculations. The different class methods then act on on those intermediate calculations and return a DataSeries of their own. So this is a two-step calculation where the intermediate DataSeries (a calculations of deviations between a symbol and .SPX) is useless without the other methods, which depend on it.

I could recompute the intermediate part for each of the three methods (I'm doing that now.), but why recompute it three times (each with external symbol calls for .SPX) when you can store it as a private class field member? Also, the intermediate calculation is kind of complicated; I would prefer not doing it three times.

I've looked through the Community Indicators or TASCIndicators, but I can't find any that have multiple methods using a common DataSeries. Can you please point me to one you know of? Is this hard to do for some reason?

Yes, I discovered C# doesn't support multiple inheritance for easy access to external symbols in derived classes; however, your suggestion for using ExternalSymbol() call for accessing .SPX in my Contrast class works great! I've been doing different decorrelations against .SPX with great success. But I don't like re-calculating the deviations intermediate (DataSeries) three times to get different decorrelation types and strengths; that's just foolish. Using several member class functions is the way to go instead, and this should be easy. Right? Or does the intermediate DataSeries have to be cached in some weird way? Won't its class instance just remain on the heap until the Strategy class exits?
profile picture

Eugene

#4
QUOTE:
but why recompute it three times

Nothing is recomputed three times if you follow guidelines properly and use Bars.Cache:

* Creating an Indicator Library in Wealth-Lab Pro > Returning a Cached Copy
* QuickRef (F11 key) > Bars Object > Cache

QUOTE:
So how do I peek at something in my Contrast class?

A. After you create an instance of Constrast, you can call PrintDebug. This is how PrintDebug is intended to work: from Strategy i.e. WealthScript-derived class.
B. Use Visual Studio's debugger. No need in Console.WriteLine, just set a breakpoint.
C. Less preferable: write the value to a file.
profile picture

superticker

#5
QUOTE:
Nothing is recomputed three times if you follow guidelines properly and use Bars.Cache:
* Creating an Indicator Library in Wealth-Lab Pro > Returning a Cached Copy
Well, caching the intermediate DataSeries should work. Thanks for the suggestion. I'll try that.
I'm still confused why my reference(s) to my private intermediate DataSeries gets lost (destructed).

QUOTE:
So how do I peek at something in my Contrast class?
QUOTE:
A. ... PrintDebug is intended to work from Strategy i.e. WealthScript-derived class.
Okay, so since my Contrast class is derived from DataSeries and not WealthScript, PrintDebug will be out of scope in Contrast. I guess I never realized PrintDebug was derived from WealthScript. Thanks for pointing that out. As a suggestion, it might be nice to make PrintDebug a "simple" member function of a low-level .NET class that's common to WealthScript and DataSeries at some future time.

QUOTE:
B. Use Visual Studio's debugger. No need in Console.WriteLine, just set a breakpoint.
C. Less preferable: write the value to a file.
Thanks for all your suggestions and quick response. I'm good now.
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).