SetGlobal, GetGlobal from DLL
Author: streak
Creation Date: 1/27/2012 9:27 PM
profile picture

streak

#1

Is any 'Reference' other than 'WealthLab' required to access 'GetGlobal', 'SetGlobal' etc from within a dll?

(I'm trying to write a dll to cover what the following script does such that it only loads the txt once per WLD session, and can return 2 vars (market capitalisation & shares issued), and display a label unless a bool is switched.

Having red wavy lines trouble just trying to get started though.
CODE:
Please log in to see this code.
profile picture

Eugene

#2
If my understanding is correct, you want this method to reside in an external library (a la Community Components), to reuse the WealthScript commands such as DrawText at the same time, and to be accessible in Strategies.

If that's the point, your code-based Strategies should pass an instance of the WealthScript object to your DLL for this to work.

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


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


As this technique is widely used in Community.Components to access the WealthScript methods, I recommend to take a closer look at its source code. Take DrawLinRegChannel for example:
CODE:
Please log in to see this code.

What you saw above is a working example of calling a WealthScript method, similar to SetGlobal or DrawText, in a DLL.

Now, in a WealthScript Strategy you do like the following snippet shows; as I said, the idea is to pass a WealthScript instance to your DLL:

DrawLinRegChannel

CODE:
Please log in to see this code.


I hope you see what I mean, because there's no way I could make it clearer.
profile picture

streak

#3
Thanks Eugene, yes you have read my concept correctly;

- The code above was to demonstrate what was needed in a dll.
- I have been able to pass an instance of WealthScript.

Finally have the code below working.

Only problem is that when Wld opens with the default workspace including a reference to the dll the Dictionary does not seem to have loaded to return data for the current symbol, and its not until the next symbol is loaded that all seems to be working fine.

Any ideas for a fix, please?

Someone may find this 'template' useful; I can generate a table of current company names, market capitalisations and total issues, each week. Then plot a label of the details and/or I guess use the details to filter Datasets - but haven't tried yet.

Sample .txt
QUOTE:

ACP,Audalia Resources Limited FPO,2832000,14160001
ACR,Acrux Limited FPO,559428949,166496711
ACS,Accent Resources NL FPO,57955078,173000233
ACU,Acuvax Limited FPO,4914191,2457095319
ACW,Actinogen Limited FPO,2523221,50464426


CODE:
Please log in to see this code.


Ah. bug. Where a symbol is not in the table a label is not drawn but the values are carried from the previous symbol. Must nuke it.
profile picture

streak

#4
made the follow edits (but still have the table not loading as the first symbol plots)

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

streak

#5
another version, without using SetGlobal(), but still not operating on first symbol! (?)

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

streak

#6
Have now fixed where the first chart plotted was not drawing the label. Was easy to find after getting debugging operative in VS Express (had a space at the end *csproj.user file path like
QUOTE:
*\WealthLabPro.exe </StartProgram>
Dumb. Anyway, fwiw, the sequence of statements in the constructor was 'off', now ...
CODE:
Please log in to see this code.
profile picture

streak

#7
A couple of other fixes;

Re plotting the same symbol was loosing the ws DrawLabel. So changed CreateChartLabel() from void to a string parked in a new property. And implemented the ws DrawLabel within the symbol property change to a reinstated DrawChartLabel(). This method is not necessary but could add an alternative like DrawText instead.

The values plotted were wrong - fixed the assigning vars.

Also wondering about speed and used StringBuilder instead of .Concat, removed the test for Dictionary != null in the symbol change property (negligible no doubt).


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

Eugene

#8
QUOTE:
Also wondering about speed and used StringBuilder instead of .Concat,

Yep, StringBuilder can offer a substantial performance benefit when working with large number of strings.
profile picture

streak

#9
Yes. Dotnetperls.com has much good quick help for C#, including speed testing on various things. Eg .Concat can be faster when concatenating less than 4 strings, but above 4 StringBuilder is it.
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).