How to tell if the script is being run via MSB vs SSB?
Author: ss161
Creation Date: 3/30/2009 10:54 AM
profile picture

ss161

#1
1. Is there a way to tell within a script whether or not the script is being run via MSB vs SSB?

for now i'm doing this, but if i click on the first symbol instead of the entire DataSource this logic will assume I'm running it in MSB mode even though it is in SSB mode.

CODE:
Please log in to see this code.


2. is it possible to have a script pop-up a dialogue box or a system console and ask for input? i put this line in the code, but it didn't work:
CODE:
Please log in to see this code.


thanks
profile picture

Eugene

#2
QUOTE:
2. is it possible to have a script pop-up a dialogue box or a system console and ask for input?

For now you can simply use InputBox this way:
CODE:
Please log in to see this code.

MSDN
By the way I just noticed it's on our FAQ.

QUOTE:
i put this line in the code, but it didn't work:

System.Console isn't practical in WealthScript but if you want to know how to make some use of it, click here:
Activate System.Console.writeline in WL5
profile picture

ss161

#3
thanks. that's very useful for me!
profile picture

Eugene

#4
This might help finding whether the strategy is being run in MSB vs SSB:
CODE:
Please log in to see this code.
profile picture

ss161

#5
Eugene, Thanks for this second part as well. It works when I'm running the strategy but when I'm debugging a strategy via SharpDevelop it crashes. I've been hardcoding the response I want while debugging and then turning this back on when I'm running the strategy for real. if you happen to think about another alternative method to determine the "mode" of how a strategy is running, that would be great. But, it is usable as it's coded.
profile picture

Eugene

#6
Sorry Steve, this is the only idea on my mind. Probably the crash has somehow to do with the usage of System.Reflection (?)

I don't have either SD 2.2 or 3.0 installed since I was disappointed by being unable to make any use of the attach-to-process feature in 3.0, but maybe I'll take a look how it goes in Visual Studio Express.
profile picture

ss161

#7
fwiw SD v3.1 has been stable for me and it allows the "attach to process".
profile picture

Eugene

#8
Didn't know about the 3.1 nightly build. Perhaps will try out someday.
profile picture

ss161

#9
I noticed in another post the use of
QUOTE:
IsRawProfitMode
from community components to tell whether a portfolio simulation or raw profit run was in progress. I'd also suggest a version of the above code that doesn't rely on System.Reflection if possible for
QUOTE:
IsSSBMode
and
QUOTE:
IsMSBMode
.

The system.reflection code works fine when using compiled code, but doesn't work when using code through one of the debuggers.

This is how I have adapted your code:

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

Eugene

#10
Using System.Reflection was the only way for this hack to happen. There's no native API call, but perhaps a good idea would be to ask Fidelity for these methods to be available in pure WealthScript.
profile picture

ss161

#11
is it possible / likely that this is now broken in 5.6?

in this block of code:
CODE:
Please log in to see this code.


this line:
CODE:
Please log in to see this code.


returns null. as a result, the p.GetValue always fails.

thanks for the help.
profile picture

Eugene

#12
The code above from 3/30/2009 12:41 PM that introduced GetSymbolNameOfActiveChart works for me in WLD 5.6, correctly telling MSB from SSB.

Note: it should not work in Strategy Monitor, like any similar hack based on usage of System.Reflection (GetDataSetName etc.)
profile picture

ss161

#13
i don't use strategy monitor.

thanks for looking. i pasted the code above into a new blank strategy. here it is:
CODE:
Please log in to see this code.


when i run the strategy i get a run-time error:


also, when debugging (in separate code, not the above) i looped through the main form controls and properties and dumped the properties and values into excel. here they are:
CODE:
Please log in to see this code.

profile picture

Eugene

#14
Wow, let us think of it. In WLD 5.6.20, the code runs absolutely fine and in WLP 5.6.20, I get the same error as you.

Probably, obfuscation.
profile picture

ss161

#15
I've made some progress, What's pasted below works, but potentially if only one strategy window is open. i'm not sure what would happen with multiple charts / strategies open. Also, I don't really know all that's going on in the internals, so if there's a better way, please comment.

Having said that, I discovered that the ChartForm contains a boolean Control labeled "MultiSymbolMode" which tells me exactly what I am looking for. I strongly believe this field, which clearly exists and is valid, should be somehow exposed in a higher level WealthScript object or at the "System" level (as is IsStreaming).

Again, I think there will be an issue with multiple strategies open, so if there's a way to know i'm finding the chart for the currently running strategy, that would be good.


CODE:
Please log in to see this code.




profile picture

Eugene

#16
Nice find. Yes, I can confirm it prints out "SSB" when multiple Strategy windows are open. The MultiSymbolMode property is probably a later addition, but seems to be global in its application, so we can't use it for reliable detection of the mode.

I'll be looking today as to why does GetSymbolNameOfActiveChart work in WLD5.6 and fail in WLP5.6. Like Robert suggested, this might be an obfuscation-related question.

btw, we've already submitted an idea to the developers to include this kind of properties (GetDataSetName etc.) in WealthScript natively.
profile picture

Eugene

#17
And the answer is: unlike WLD 5.6.20, the MainForm class is obfuscated in WLP 5.6.20, that's its Symbol property has become invisible.

Strangely, substituting "MainForm" with "ChartForm" didn't work.
profile picture

ss161

#18
this seems to work with multiple strategies open. not sure it will always work though.
CODE:
Please log in to see this code.

profile picture

Eugene

#19
Really good. That "IsBusy" trick is creative.

btw, is there a practical reason to tell MSB from SSB?
profile picture

ss161

#20
in my opinion, there are many practical reasons.

here's two code fragments showing how many of my programs start:
CODE:
Please log in to see this code.

profile picture

Eugene

#21
Thank you.
profile picture

LenMoz

#22
Both the method in this thread (giving Object reference not set) and the method in the Wiki (giving Illegal cross-thread operation) fail for my WLP release 6.7.18.0. Any suggestions? This is related to a Particle Swarm Optimizer enhancement request.
profile picture

Eugene

#23
This is caused by a decision to obfuscate the code committed by Fidelity. Sorry.
profile picture

kribel

#24
Hello All!

I am using the code from post #18 and experiencing the following problem.

Problem:
Running in optimization mode on a full dataset I get the information that the strategy is running in SSB mode.

Any ideas why?

Another question:
Is there a way to determine that the strategy is being optimized?

Many thanks
Konstantin
profile picture

Eugene

#25
Hi Konstantin,

QUOTE:
Any ideas why?

Please see my reply in post #23.

QUOTE:
Is there a way to determine that the strategy is being optimized?

You can determine that the Strategy is not being operated in Strategy window (see QuickRef, ChartPane Object > IsPricePane Property or Cosmetic Chart > ChartStyle Property). Running under optimizer is identical in this sense to running under the Strategy Monitor.
profile picture

Eugene

#26
ATTENTION: Community Components has a new GetMode function since v2017.09. It supersedes the Wiki article and related forum conversations. Thanks vladl2015 for the code.

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