Discrepancy between ConvertDateToBar behavior of Bars and DataSeries?
Author: mkbryan
Creation Date: 4/8/2015 10:52 PM
profile picture

mkbryan

#1
After looking through the Forum and the wiki, there doesn't appear anything like this issue. See the source code below.

Here's the recipe for the runtime error (null reference):
1) Switch between running with only line #37 or line #38 compiled.
2) With only line #37 compiled (and line #38 commented out), the runtime error occurs
3) With only line #38 compiled (and line #37 commented out), there is no runtime error.

There is an unexpected difference between the Bars.ConvertDateToBar and the DataSeries.ConvertDateToBar methods.

While I'll be using the QuickRef documented Bars method to move forward, can anyone explain the different behaviors?


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

Eugene

#2
Imagine that, I seem to not have had any necessity to use DataSeries.ConvertDateToBar before (vs. Bars). It works if creating a DataSeries the conventional way, though:

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

mkbryan

#3
Thanks for checking that out, Eugene.

The odd behavior comes from the TOSData object call to ConvertDateToBar and TOSData is derived from DataSeries. ConvertDateToBar is not defined in TOSData and is not virtual AFIK so the DataSeries method should be called. What is the source line that declares the DataSeries ConvertDateToBar method?

The null reference issue may be more of a .NET or C# runtime issue, but it is real and should probably be viewed as a "Beware of Pitfall" sign to other WealthScript developers.

In any case, there are ways to avoid this. Namely using the Bars method or the DateTimeToBar method of WealthScript.

For now, I'll put this one in the "Newbie stumbling" category. :-)
profile picture

Eugene

#4
Marc,

Out of curioisity, what objective are you trying to reach with that design pattern?
profile picture

mkbryan

#5
I'm setting up an infrastructure to port thinkscript code that has already been validated. There are some particularly long sections of thinkscript code, and the port would be error prone. The error risk is due to thinkscript data access, which is relative to the current bar. For example, in thinkscript, open[1] refers to the prior bars open price. Because of the length of code I'm porting, the goal is change as little of the thinkscript as possible to get the same results running in WealthLab. The TOSData indexer (which was left of out the example code) and operator double provider the relative bar data access into a DataSeries.

Also, the thinkscript is used on multiple timeframes, but manually, i.e. the human looks at multiple charts, which are each in different timeframes. So the ConvertDateToBar will facilitate the multi-timeframe analysis within WealthLab. My evaluation of WealthLab is based on (among other things) making the multi-timeframe analysis part of a Strategy. WLP seems to offer the means to this end. The proof in the pudding.

BTW, since the example code, I'm using the very handy GOP for the DateTime and Bars objects.
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).