Attaching a new library to use in Strategy code
Author: ss161
Creation Date: 2/23/2009 8:49 AM
profile picture

ss161

#1
i'm very new to C# development

i have a library of (c#) statistical routines that i would like to be able to call from my wealth-script strategies -- i'm assuming by including a "using" statement at the top of my strategy.

i don't know how to compile and create the library so that it can be included in other scripts. right now i'm only using the editor and compiler included in Wealth-LabPro v5.3.

thanks for the help.
profile picture

Eugene

#2
<<i have a library of (c#) statistical routines>>

The answer will depend on whether it's a compiled library i.e. a DLL already, or these are just source code (e.g. a Visual Studio project or individual .cs files).
profile picture

ss161

#3
i guess the answer to both compiled libraries and straight source code would be helpful, as i think about it. i have dlls for the specific library that brought about the question, but in the future i will also want to be able to attach libraries directly from source code.
profile picture

Eugene

#4
1) For the compiled library it looks like you already know the answer i.e. including a 'using' directive at the top of your Strategy.
2) To use individual classes and routines they must be included in the Strategy code.
profile picture

ss161

#5
per item 1) i don't know how to include the code; i have a dll, but i don't know how to instruct wealth-lab where to find the dll so that it can be included with the "using" statement. let's say the dll sits in c:\Users\Steve\Libraries\MathNet\MathNet.Iridium.dll. How do i instruct wealth-lab to point to that library?

per item 2) if i have some compiled strategies that i want to include in other strategies, in prior versions of wealth-lab i'd use the $include statement. is something like that available in the c# / .net environment?

thanks
profile picture

Eugene

#6
1) Strategy editor - References... - "Other Assemblies to Reference"
2) What's the point of including a compiled strategy in other strategy? You can mimick the use of the $include statement with the 'using' directive.
profile picture

ss161

#7
1) thanks. i didn't know how to include the reference.

2) i've written and compiled code that creates a "trend" class based on some of the usual higher high / lower low methods. in a new strategy i want to use the trend class in addition combined with some other rules -- in this case using CCI. once i've compiled my trend class in wealth-lab, can i add it as a reference using the Strategy editor - References as you described above? would i need to compile it as a dll using visual studio or some other tool?

thanks again, i was lost on the dll part above.
profile picture

Eugene

#8
You're welcome.

2) Yes/yes - you can use the class by adding a reference using the References dialog / it should be a compiled DLL.
profile picture

ss161

#9
i'm missing something. assuming it's something obvious i aplogize in advance.

my objective is to link in the dll of the opensource Math.Net numerical analysis library: http://mathnet.opensourcedotnet.info/. It seems like it could be a very usefule library to many wealth-lab users.

i download the software (i only really care about the dlls, but the source is available as well) and (thanks to your help above) add a reference in my program to the dll. i then run a very simple test program. the program compiles, but when i execute the program i get the following error: "Runtime error: Could not load file or assembly 'MathNet.Iridium, Version=2008.8.16.470, ... or one of its dependencies. The system cannot find the file at WealthLab.Strategies.MyStrategy.Execute().

Here is my code:

CODE:
Please log in to see this code.


in the References area, i've added a reference to the dll.

Now, separately, as a different test, i start SharpDevelop ("The Open Source Development Environment for .NET"): http://www.icsharpcode.net/OpenSource/SD/ -- I've just started trying to use it, and am not that familiar with it yet. but, I write this simple program and build it with SharpDevelop:

CODE:
Please log in to see this code.


basically the exact same sample code to test whether the MathNet Numerics library is loaded. Again, I add a reference to the MathNet dll (the exact same reference as i do in wealth-lab). I build the application and then run it and ... it works fine. It opens a console, writes Hello World! and then 0.797. and then press any key ...

I can't figure out why the library attaches in SharpDevelop but does not attach in Wealth-Lab. The program does compile in Wealth-Lab after selecting the dll so it does see the dll.

Steve


profile picture

CandCB

#10
The short answer The new dll must be in the same directory as WealthLab.dll. but it's not that simple.

For the long answer see Ask Glitch in the WeathLab FAQ ""How can I debug my trading strategies."
profile picture

ss161

#11
thanks for trying. coincedently i had just read that Wiki FAQ page as i'm starting to use SharpDevelop but didn't get the "long answer" reason that you referenced.

however, anyway, i deleted the reference to the dll in its original location, copied the dll to c:\program files\fidelity investments\wealth-lab pro 5\ -- where WealthLab.dll exists, and i still get the same run-time error.

after adding the reference, when i go back into the References pop-up, under Other Assemblies to Reference i see: c:\program files\fidelity investments\wealth-lab pro 5\MathNet.Iridium.dll

i'm assuming that i'm missing some other file dependencies, although i can't figure out why SharpDevelop doesn't have any issues with the dependencies not being there.


thanks again.
profile picture

ss161

#12
I just copied the entire directory of files over from the MathNet Binary\Release folder instead of just the MathNet.Iridium.dll. i reattached just the MathNet.Iridium.dll, and it worked.

Thanks very much! it was a head pounding day for me.
profile picture

Eugene

#13
Looks like you don't even need to add a reference to MathNet.Iridium.dll as long as the DLL already exists in WLP main folder.
profile picture

ingber

#14
I have DDLs that work fine in Excel & TradeStation. They are developed from sets of C code that are compiled under gcc or under g++. They have no COM wrappers. The input params are simply market data (price, volume, current positions) and the output params are simply execution orders at the next epoch. The input and output could via direct calls or even short files if that is easier. The latter would require writing an input file, calling my files as an executable, and reading back a file set by my executable. This is not as clean as the former direct communication between WLP and a DLL. I just do not want to rewrite 50K lines of code.

Are these viable DLLs to be processed if they are simply dropped into the WLP folder as suggested above? Are there some examples in WLP of such usage?

Thanks.

Lester
profile picture

Eugene

#15
Wealth-Lab .NET is a fully managed application rewritten from scratch under .NET 2.0. If the DLLs have no COM wrappers, they will not be recognized when simply dropped into the WLP folder. You need to create a COM callable wrapper for them.
profile picture

ingber

#16
As I wrote on 11/8/2009, I have DLLs without COM interfaces that work fine in Excel & TradeStation.

I'm now working with someone to prepare a COM interface for my DLLs so I can use them in WL.

A query has surfaced: Do I need to also prepare an IDispatch interface [http://en.wikipedia.org/wiki/IDispatch]?

Thanks.

Lester
profile picture

Eugene

#17
Lester,

I'm by no means a COM expert, but having IDispatch won't hurt for sure - if you need to use late binding.
profile picture

avishn

#18
After migrating to Windows 7 I've lost ability to compile and write my assembly's DLL from SharpDevelop to Program Files/Fidelity Investments/Wealth-Lab Pro 5 folder. Of course, this is something to be expected, because Windows 7 has all that new UAC security stuff. Now what I'm trying to do is to use some other output directory in SharpDevelop and then use "Reference..." link in WLP to link to it from within my strategy. The strategy seems to compile fine but when running it complains about not being able to load my library or one of it's dependencies. I have all dependencies for my DLL assembly in the same output directory, and, in fact, they are also available in the main WLP directory (ZedGraph.dll and such). I'm not sure how to resolve it. I would hate to run SharpDevelop as administrator or to keep a command prompt open w/ elevated security just to be able to copy a dll file to Program Files/WLP folder. One of the posts in this thread kind of implies that DLLs need to be in the same directory as WealthLab.dll, but that raises the question about why there's a "Reference" link in the Strategy window to start with. What's the recommended approach of solving this?
profile picture

Eugene

#19
When I need to debug something on Vista/7, I just load VS as admin. Elevated privileges are required to copy something to Program Files or the root of the system drive. Perhaps running a known open-source app as admin is much lesser evil than disabling UAC at all.
profile picture

avishn

#20
Ok, thanks.

Also, do I take it as the "Reference.." link in the strategy is absolutely redundant? It seems that if you put DLL into the main WLP directory it "automagically" becomes visible to the strategies anyways, and it won't work if you put your DLLs into any other folder (so there's no point in explicit "Reference" in either case).
profile picture

Eugene

#21
Yes, it becomes available once placed into the main WLP folder, so you'd want to Add Reference to a DLL located elsewhere.
profile picture

jalalfeghhi1

#22
Eugene, Avishn, All
I have a very similar problem, using Visual studio 2010 and wlp6. I have build a strategy dll but when I drop it in the main wlp installation folder WLP does not see the new strategy. Eugene mentioned that I have to provide a call wrapper but the documentation located under http://www2.wealth-lab.com/WL5Wiki/kbAskGlitchDebug.ashx?HL=visual,studio does not mention this all all. Do I have to provide a com wrapper? How do I do this under visual studio 10?

Thanks
profile picture

Eugene

#23
profile picture

jalalfeghhi1

#24
Eugene, do appreciate your quick response. Which .NET version is supported then? Would I still need to create a com wrapper do just drop it under the wlp main installation directory? No need to use the Add Reference in this case?
profile picture

Eugene

#25
1 - .NET framework versions 2.0 through 3.5 are supported for creating any extensions to Wealth-Lab. .NET 4.0 is not going to work as of v6.0.

2 - I can't answer this question (whether you need to create a COM wrapper or not) because I have no idea about your task. It's up to you.

3 - Depends on DLL placement. No need when the DLL is dropped under the WLP main installation directory, otherwise you need to use the "Add Reference" dialog.
profile picture

jalalfeghhi1

#26
Eugene,
I targeted .NET 3.5 and now I see my dll, did not need the com wrapper, thanks so much :-)
profile picture

jalalfeghhi1

#27
Eugene,
I am almost at the last step of the guide, it mentions that "In Visual Studio, select Debug/Attach to Process from the menu. Find and select the Wealth-Lab process." Visual Studio 2010 express does not have Debug/Attach, how can I get around this?

-thanks
profile picture

Eugene

#28
profile picture

jalalfeghhi1

#29
Eugene,
Thanks again. I did create a new file called myProjectName.csproj.user, put it in the directory where my project is and pasted the following lines:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<StartAction>Program</StartAction>
<StartProgram>c:\Program Files\Fidelity Investments\Wealth-Lab Pro 6\WealthLabPro.exe</StartProgram>
</PropertyGroup>
</Project>


VS express 2010 does not recognize this new file and does not launch wlp, could you please point out to some possible reasons?

-Best, J
profile picture

jalalfeghhi1

#30
Eugene,
Sorry, had to put the file one directory lower, things seem to be working fine, thanks :-)
profile picture

Eugene

#31
You're welcome.
profile picture

jalalfeghhi1

#32
Eugene,
Evreytime I make a change to my strategy, Visual Studio needs to relaunch the wealthlab, which is a time cousuming process. Is there anyway we can streamline the debugging process, or is this the nature of the beast?

-thanks, J
profile picture

Eugene

#33
Someone should know better but I have nothing to add:

a way to debug using Visual Studio without having to restart WLP 6 ?
profile picture

jalalfeghhi1

#34
Eugene, I understand, thanks.
profile picture

JDardon

#35
My 2 cents on what worked for me:
I had the exact same problem as ss161 and jalalfeghhi1 and came to three conclussions:
1) Placing all the files in the Wealth lab folder makes no difference.. the only one that Wealth Lab really cares is the .dll.
2) The only way I got it to work with a .dll compiled by Visual C# Express was to compile for a .NET 2.0 and turn on the flag for the Assembly (Project Properties -> Assembly Information) "Make assembly COM-Visible". When I turned on that flag, rebuilt the .dll and replaced it in the Wealth lab folder the strategy that used my compiled library recognized it and worked flawlessly. I didn't see this mentioned anywhere.
3) Unless I restart Wealth lab after copying the object .dll to the Wealth Lab folder, Wealth Lab doesn't seem to recognize it (perhaps due to some Windows Caching, I'm not sure).

Once I got everything to work properly, I retried eliminating the .dll from Wealth Lab and use the "Add Reference" option for the strategy and I onl confirmed that it doesn't really work as explained, Wealth Lab seems to only recognize the .dll's added in the Wealth Lab folder.


Hope it helps somebody.

profile picture

Eugene

#36
1 - What do you mean by saying "all the files"?

2 - Enabling COM visibility is not required at all. That's a generalization. No known extension is compiled with this option enabled.

3 - Because Wealth-Lab only scans for libraries (Indicators, PosSizer etc.) on startup. Method/function libraries don't require a restart.
profile picture

JDardon

#37
1) I was referring to ss161's post:
QUOTE:
just copied the entire directory of files over from the MathNet Binary\Release folder instead of just the MathNet.Iridium.dll. i reattached just the MathNet.Iridium.dll, and it worked.


2) Strangely, whenever I disable the COM visibility option in Visual c# express, recompile, and replace the .dll I get the same error as the people posted previously. When I reenable it and re place the .dll it works.

3) I have my windows vista using the ReadyBost cache option for files in a flash card, I am suspecting that it could be causing the previous version to be accessed from the cache, because replacing the .dll in the wealth lab folder is insufficient in my installation, the restart of Wealth lab is required for the new .dll to take effect.

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).