Doing Strategy development in Visual Studio and inherit the interface in WLP
Author: algtrader
Creation Date: 10/11/2017 5:13 PM
profile picture

algtrader

#1

Hi Eugene,

I want to do the bulk of my strategy development using
VisualStudio (I use VS community 2017). With that in
mind, I want to implement strategies in such a way that
my source code looks like:
#1 on the Wealth Lab Pro side, and
#2 on the VS side.

Problem:
VisualStudio compiled everything with no complaints. The generated
libs were copied to: ".../Fidelity Investments/Wealth-Lab Pro 6/." ,
and WLP was re-started. WLP didn't display any errors when "Compile"
was pressed.

However, WLP does absolutely nothing.

Any ideas? I would really want to make this work, because it would
simplify so many things. For example, there's only 1 source code
to manage. No more cut/paste between WLP and VS, and sometimes losing
track of which one is the "current" version.

Thanks in advance.


/ALG


// ======================================================================
// 1. On the Wealth Lab Pro 6 side....


CODE:
Please log in to see this code.




// ======================================================================
// 2. On the VisualStudio side...



CODE:
Please log in to see this code.



CODE:
Please log in to see this code.




profile picture

Eugene

#2
Hi Al,

Since you're asking me, I can't remember having tried this proxy pattern with regard to WealthScript Strategies. ¯\_(ツ)_/¯ So I have to take your word on that it does nothing. ;) Maybe there's some trick that doesn't come to my mind now, maybe the lack of StrategyHelper interface implementation, I don't know.

At least you can go the beaten path:

1. add a reference to your compiled function library (with setLogger, prLn, whatever)
2. edit the template code
3. save it by clicking Edit > Set as Default Template Code
profile picture

algtrader

#3

OK I get it. From doing a bunch of test compiles I figured out that WealthLab.WealthScriptCompiler (the class that compiles the strategy code in WLP) has to know which instance of the WealthScript class to construct. It does this by examining all classes defined in the WLP strategy source code. The first non-abstract class whose immediate parent base class is WealthScript will be instantiated and used.

Luckily, WealthScriptCompiler only looks at the base name of the class, and not the fully qualified class name. Hence, the below solution works.



// ======================================================================
// 1. On the Wealth Lab Pro 6 side....


CODE:
Please log in to see this code.




// ======================================================================
// 2. On the VisualStudio side...



CODE:
Please log in to see this code.



CODE:
Please log in to see this code.



profile picture

Eugene

#4
Al,

Glad you were able to find the solution on your own. Thanks for your contribution.

P.S.
Note to future posters:

This is a very specific, self-contained topic. If you have a general question re: Strategy development in Visual Studio, please ask it in a different thread. All questions not related to this design pattern will be cleaned away.
profile picture

superticker

#5
If I'm understanding the last couple code blocks right, this also illustrates how to "override" or actually supersede/overload some WealthScript members with member functions of one's own design. I'm assuming C# works like C++ in this regard, but I may be wrong. I have noticed to truly override/overload inherited C# class members, they typically have to be declared as "virtual" within the (WealthScript) base class. Not the case with C++, though; C# maybe more restrictive. Perhaps someone could clarify if base-class overloading is somehow possible in C# without the virtual qualifier in the base class.
profile picture

algtrader

#6
Just to clarify... In C#, the terms "override" and "overload" are very different.

Overloaded functions are functions with the same name, defined in the same scope, but having different parameters.
In the below example, calling foo(123) will call the function overload foo(int i), and foo("test") will call function overload foo(string s).
CODE:
Please log in to see this code.



In C# function overrides are the means of implementing new behavior in a subclass (ie. different from the parent class).
Only virtual or abstract functions may be overridden. The whole concept is a bit more involved, but googling "C# override"
should give good references (the first one, by Microsoft, explains it all).




profile picture

superticker

#7
QUOTE:
In C# function overrides are the means of implementing new behavior in a subclass (ie. different from the parent class).
Only virtual or abstract functions may be overridden.
So I can use the approach in post #3 to overload existing WealthScript functions, but not override (modify their behavior totally) them because WealthScript isn't an abstract class and lacks the virtual qualifier on its class members. Thanks a bunch for the clarification. I think C# rules preserve the purity of the language (i.e. its class functionality) better than C++. Interesting.