Write to status bar on chart window
Author: Panache
Creation Date: 1/8/2019 1:54 AM
profile picture

Panache

#1
Eugene,

Is it possible for a strategy to write to the status bar on the chart window (as opposed to the main status bar)?
profile picture

Eugene

#2
Kurt,

I remember the solution you're referring to but before I look into the new challenge, could you tell me what's the point in writing to the chart's status bar? What's your objective here if you're free to print or draw on the chart itself?
profile picture

Panache

#3
I wrote a bare-bones optimization wrapper which can be incorporated into a strategy to solve the problems I've been having with the Wealth-Lab optimizer randomly skipping strategy parameter combinations. I'm still testing it, but so far, it hasn't yet missed a combination and is incredibly fast (In my limited benchmark testing, it averaged 7 times faster than the built in optimizer). When I've run it 24 hours a day for a week, I'll consider it trustworthy. At that time, I'll post the results in the original thread.

Anyway, since optimizations can run for a long time, I want to periodically let the user know where the strategy is in the optimization. The way it is currently written, it updates the main status bar each time the first parameter changes. That gets confusing when multiple optimizations are running, so I added some information about which strategy generated the new update. That still limits the user to only knowing which was the most recent strategy to update and having no idea where the other strategies are in the optimization process.

I thought about using the debug window to have a real time log, but for now, I'm using the debug window to display combinations with no trades, so I can check them when the optimization is complete. Therefore, I can imagine all kinds of problems if several strategies are writing different things to the debug window.

I tried using DrawLabel and DrawText, but the "update" isn't displayed until the strategy is done executing. If there's an equivalent to FlushDebug for a chart window, that might be a viable option.

I thought the best solution (if it is possible without a lot of overhead) is to have each strategy write to the status bar on it's chart window. That way, at any time, the user could click on a chart window and see where that strategy was in the optimization process.
profile picture

Eugene

#4
Wow, what a creative approach. You never know where Wealth-Lab's extensibility might bring you up to.

To answer your question: yes it's possible. Check out example below suitable for pasting in a Visual Studio project. Add reference to WealthLabPro.exe /WealthLabDev.exe for WLD users/ - just not .exe.config of the same name. It's unlikely that you're going to make it work in WL's built-in Editor as it throws an error on attempt to reference the *.exe file.

Naturally, this code should not work in Strategy Monitor, Combo Strategy or other 'headless' scenarios. You might want to detect it: see IsPricePane Property in the QuickRef.

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

Panache

#5
Thank you Eugene.

Unless I'm missing something, if there is more than one strategy window open in Wealth-Lab, your code writes the same message to both PricePanes and status bars. You can substitute
CODE:
Please log in to see this code.
for
CODE:
Please log in to see this code.
to test this. This results in the same lack of clarity for my purposes as simply using PrintStatusBar();

How can I only write to the status bar of the strategy being run?

On a separate note, with a slight modification, this can be called from a strategy with the built in editor. First, modify your code as follows:
CODE:
Please log in to see this code.

Compile that as a class library in Visual Studio targeting the Wealth-Lab directory.

Next open Wealth-Lab>New Strategy from Code, and paste the following code into the Editor:
CODE:
Please log in to see this code.

Add a reference to whatever you named your class library, and Run the Strategy.
profile picture

Eugene

#6
QUOTE:
Unless I'm missing something, if there is more than one strategy window open in Wealth-Lab, your code writes the same message to both PricePanes and status bars.

It's proof of concept which shows that it can be done. What message to put in their status bar is now up to you.
profile picture

Panache

#7
I'm sorry if I wasn't clear. The way it is written, if there is more than one strategy window open, when the code is run in one strategy window, the status bar on all open chart windows changes. My question is how can I only change the status bar of the chart window of the strategy being run?

Asked another way, how can identify which strategy window is active? Obviously Wealth-Lab has some way of distinguishing among multiple strategy windows, since the information displayed in the chart window status bar is unique to that strategy.

profile picture

Eugene

#8
Well, it's evident from the code itself that the status bar will change on all open chart windows. In its current state the dummy strategy just 'broadcasts' same string to all S. windows using a foreach loop. That's why I called it proof of concept.

How Wealth-Lab distinguishes among different Strategy instances? I think it puts them in an internal list which in theory you could try to access with Reflection. But I wouldn't recommend going this intricate way.

To help you identify the S. window the dummy strategy's code already draws some key fields on the chart: Strategy class, name and GUID, current Symbol/DataSet it's being executed on, along with the position size. There may be other useful properties like DataRange. Let the forum know if this helps you distinguish the active S. window.
profile picture

Panache

#9
I was hoping there was a unique identifier for each instance of a strategy, but I didn't see any unique chartform properties. I appreciate your confirming that I wasn't missing something.

As you suggested, the only way I could see to do it was to look at the combination of properties which made each strategy unique from the others which may be open. Unfortunately, that is probably either very user dependent or would require comparing a lot of properties.

Again, thank you for the effort you put into your proof of concept.
profile picture

Panache

#10
OK. Maybe I gave up too quickly. The following code identifies different strategies by strategy name, data range, data set name and optionally symbol.

Create a class library using Visual Studio by inserting the following code and adding the references indicated in the comments, targeting the Wealth-Lab program file directory for the output:
CODE:
Please log in to see this code.


Next open Wealth-Lab>New Strategy from Code, and paste the following code into the Editor:
CODE:
Please log in to see this code.

Add a reference to whatever you named your class library, and Run the Strategy.

If you have multiple strategy windows open, as long as each has a different combination of strategy name, data range, data set name and optionally symbol, the PrintChartStatusBar command will only change the status bar of that strategy.

For the optional symbol match, I used
CODE:
Please log in to see this code.
to determine the symbol being used by the strategy being run. If
CODE:
Please log in to see this code.
is active when PrintStatusBar is called, I believe it will not work, because the chartform symbol will still the the original symbol in the data set. I didn't test this since it is not a meaningful distinction for me. However, before you use the optional symbol criteria, you might want to test it and/or use a different method of determining the symbol being used by the strategy.

PrintChartStatusBar is actually about 20% faster than PrintStatusBar (and it would probably be faster if I built the code for release instead of debug). Nonetheless, calling it too frequently in a strategy will have an effect on the strategy run time. On my slow i5, 10,000 calls took about 14 seconds.
profile picture

Eugene

#11
Nice job!

Also, the chartform.WealthScript.ParameterString property may be used to distinguish between Strategy instances with identic data range but different Strategy parameter values.
profile picture

Panache

#12
I couldn't have done it without you.

Feel free to add it to Community Components if you want.
profile picture

Eugene

#13
QUOTE:
Feel free to add it to Community Components if you want.

Hmm no, that'd require adding a reference to WealthLabDev.exe (which WLP customers don't have and vice versa for WLD) to C.Components. We can't do that.
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).