Determining the Chart scale programmatically
Author: superticker
Creation Date: 5/26/2016 3:08 PM
profile picture

superticker

#1
I'm trying to determine the time scale the chart is set to via WealthScript. The first line works beautifully. It will even return "Weekly", "10 Minute", or whatever the scale is set to regardless of whether the chart is displaying intraday data or not.

The second enumeration-type approach is suggested by Visual Studio. It returns "False" regardless of what the chart scale is. Why is this not working? Are the data types incompatible, and if so, why don't I get a compilation error?
CODE:
Please log in to see this code.

Now when I try to use the first one in the code below, I get inconsistent results. With some stocks, it works just fine. With most stocks, the intraday scales are recognized as "Daily". With a few stocks, I get nothing (probably because it's in a try{} block and I haven't handled the "general" run-time error case). Why is this failing?

CODE:
Please log in to see this code.
This code is occurring inside a DLL library, so an instance of the WealthScript object is being passed in as WSObj. Just remove that part if you're call it directly.
profile picture

Eugene

#2
Simply use this for making comparisons:

CODE:
Please log in to see this code.


The Bars.Scale property is also documented in the QuickRef, near DataScale.
profile picture

superticker

#3
You mean use:
CODE:
Please log in to see this code.

Thanks. I'll give that a try after I reboot WL at the end of the trading day.

I thought the above statement would return the scale the data is store as inside the Bars object rather than the scale the chart was using at the time to display the data. (Maybe the two are the same.)
profile picture

Eugene

#4
Bars.Scale automatically returns the chart's scale.
profile picture

superticker

#5
The new line of code:
CODE:
Please log in to see this code.

Seems to work even poorer than the original line above. The "30 Minute", "15 Minute", "10 Minute" cases all show up as Daily. And much of the "Weekly" cases also show up as "Daily". And there are stocks that don't print anything for this line even though a general exception catch{} case has been defined. Clearly we are missing something important, but what is it?

With the original line above, it least it worked correctly for some stocks. But about 20% stock cases are just wrong. How can that be?
profile picture

Cone

#6
Your snippet contains references that have no context here. When run in the Execute() method of a script, the following snippet always shows the correct scale (for me).

QUOTE:
DrawLabel(PricePane, Bars.Scale.ToString());
profile picture

Eugene

#7
Bars.Scale/DataScale is precise and is never wrong. The context matters. If you show me exactly how to reproduce the anomaly using a complete code sample and provider / symbol / bar scale, I'll try to find out what you're doing wrong.
profile picture

Cone

#8
This always works for me without a problem - always Blue for Daily and Cyan for any other scale.

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

superticker

#9
QUOTE:
Bars.Scale/DataScale is precise and is never wrong. The context matters.
Thanks guys. Yes, there's something I'm overlooking in the context somehow that's indeterminate between stocks. I'm going to try to strip the code down to the simplest case (as Cone has done above) this weekend to try to locate the problem. I guess the line in question is basically correct, so I need to explore somewhere else.

UPDATE: I found the problem. There exists multiple DrawLabel(...,Bars.Scale == BarScale.Daily ? Color.Blue : Color.Cyan) statements, and I missed fixing one of them. Sorry for the confusion, and thanks for all your help.
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).