Is it possible to create a class library in Wealth-Lab?
Author: Panache
Creation Date: 10/4/2018 6:57 PM
profile picture

Panache

#1
My strategies use a lot of common code, and only a small portion of the code in each strategy is unique to that strategy. Is it possible to create as class library or something similar in Wealth-Lab which would allow my strategies to just contain the unique code and call the class library for the common code. The following is a toy example to demonstrate what I would like to do:

CODE:
Please log in to see this code.


Apart from making my strategies much smaller, if I do have to make changes to my common code, I would only have to make the change once in the class library instead of changing each strategy.
profile picture

Eugene

#2
Answer: yes, of course as per the Wiki FAQ: Is there a way to reuse a function in Strategies? Is it possible to create a library of reusable functions?

Furthermore, most likely you're already a user of such library - it's called Community Components. Check out its open source code on how to call WealthScript methods (SetContext, BuyAtMarket) and objects (Bars) from a custom DLL. The notation is slightly different from what you're used to. Here's a quick example of what I mean:

https://www.wealth-lab.com/Forum/Posts/Simple-example-using-WealthScript-as-class-library-from-Visual-Studio-34034

profile picture

Panache

#3
Thanks Eugene.

I assumed I could call a .dll created in Visual Studio, but I was hoping to be able to program it directly in Wealth-Lab. I'll have to play with programming strategy code in Visual Studio.

I saw the forum post before I started this thread, but I'll see if Community Components is more helpful.
profile picture

Panache

#4
I solved my own problem.
profile picture

Eugene

#5
This does generate a trade for me. Have you ever used AutoStops, EnterAtPrice/ExitAtPrice (or Limit On Open Orders), ImportHistoricalTrades or Interacting with Portfolio Equity? In C.Components they've all been serving the same purpose to its many users.
profile picture

WLP123

#6
QUOTE:
but I was hoping to be able to program it directly in Wealth-Lab. ... I solved my own problem.


Kurt, would you elaborate on your solution? Were you able to do this without having to use Visual Studio and creating a .dll?
profile picture

Eugene

#7
QUOTE:
I solved my own problem.

Shortly after seeing my reply author has edited his post, removing his question and some example code. That's why the confusion i.e. his post #4 looking like the answer to post #1 (it's not).

QUOTE:
Were you able to do this without having to use Visual Studio and creating a .dll?

You can refer to the FAQ in post #2 on this one. It holds true.
profile picture

WLP123

#8
OK, thanks for clarifying Eugene. I'll refer to the FAQ again.
profile picture

Panache

#9
I'm using Virtual Studio to create a .dll.
profile picture

Panache

#10
QUOTE:

https://www.wealth-lab.com/Forum/Posts/Simple-example-using-WealthScript-as-class-library-from-Visual-Studio-34034

I'm assuming Edit and Continue doesn't work when building a class library because Wealth-Lab keeps the class library in memory, so it has to be restarted to use the rebuilt class library, or am I missing something?
profile picture

Eugene

#11
No need to assume. ;) Check out this step by step tutorial, there's a section at the bottom on how to get Edit and Continue working:

Programming | How can I debug my trading strategies in Wealth-Lab?

E&C works like a charm. In case you haven't seen these forum topics they may provide some extra insight on it:

Developing class library w/o shutting down WLP on each rebuild
Using Visual Studio 2015 and 2017 for debugging
profile picture

Panache

#12
Thank you so much. I hadn't seen the second one, which is why I only thought it applied to building strategy code. I installed the community edition of Visual Studio 2017 and it does work like a charm. I can't believe how many hours I've wasted using my pro version of Visual Studio 2013!

fyi - I saw a great suggestion on stackoverflow to make the Break Mode tab very small and then drag and attach it to the Call Stack window, making it much easier to ignore.
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).