Calling DrawLabel() inside a class member function
Author: superticker
Creation Date: 5/1/2016 7:52 AM
profile picture

superticker

#1
I'm trying to create some reusable functions across strategies within a WLTrading class. Can someone please tell me how to assign the "chartFunction" object below so chartFunction.DrawLabel() can be called successfully?
CODE:
Please log in to see this code.
profile picture

Eugene

#2
Check this out - to pass WealthScript object by reference:

Example 1:
CODE:
Please log in to see this code.


Example 2 by Aleksey:
CODE:
Please log in to see this code.



Then I recommend studying the Community Components code as a real life example of how it's done:

Home - Community Components

It's used virtually everywhere.
profile picture

superticker

#3
Thanks. Your first link has allowed me to fix the WLTrading class code. It compiles now. The solution is at the bottom.

But there's a new problem with the Main strategy code below. It returns an "Object reference not set to an instance of an object" run-time error. This is also reproduced as an attachment. I just don't see why there's an object reference error.

CODE:
Please log in to see this code.



The WLTrading class code below now compiles as expected.
CODE:
Please log in to see this code.
profile picture

Eugene

#4
It's pretty strange that this script compiles for you without a parameterless constructor being defined...
CODE:
Please log in to see this code.

To get rid of the exception, you should preface all of your PricePane, Bars et cetera with "WSFunction." as well. For example:
CODE:
Please log in to see this code.
profile picture

superticker

#5
QUOTE:
To get rid of the exception, you should preface all of your PricePane, Bars et cetera with "WSFunction." as well. For example:
CODE:
Please log in to see this code.

That was the fix. Thanks a bunch! I'm going to have to port the main strategy to the Visual Studio IDE so I can use the debugger to properly locate all these bad NULL references.

There's one more remaining problem. Apparently, the Gics functions (see code below) need to be called by reference as well. So if the Gics functions aren't type "WealthScript", then what type are they, and how do I capture that type in the main program? (I'm assuming I pass their type the same way I pass the WealthScript reference.)

UPDATE: The Gics functions are of type "string" (says the Programming Guide)? So why would a reference to them need to be passed from the main program in the first place? Why am I getting NULL references to these functions if the code compiles correctly? I'm "assuming" Visual Studio would gripe if it couldn't find WealthLab.DataProviders.Gics, but I could be wrong. I'll have to look into that further.
CODE:
Please log in to see this code.

QUOTE:
It's pretty strange that this script compiles for you without a parameterless constructor being defined.
These are not static methods. They require a reference to be passed. But if they were defined as static as with an Extension Method, then you may be right about needing the parameterless constructor.

I've never defined an Extension Method before, but their syntax does provide for cleaner code, and I like that. I may try to define these methods that way later (after I get things running).
profile picture

Eugene

#6
The Gics class itself is certainly not of type string. You should be able to find the type and the source assembly using Visual Studio's Object Browser.
profile picture

superticker

#7
QUOTE:
The Gics class itself is certainly not of type string.
The Visual Studio Object browser says it's of type Gics. But when I try to declare ...
CODE:
Please log in to see this code.
VS says it's a static type. If it's really a static type, then the Gisc methods are passes as Extension Methods (not by reference) and the code ...

... oops I see the problem. The code below now works. Thanks for all the help.
CODE:
Please log in to see this code.
profile picture

Eugene

#8
Glad you've found the solution.
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).