How to read double[] into DataSeries / use LINQ on DataSeries
Author: stolmax
Creation Date: 8/17/2009 11:26 PM
profile picture

stolmax

#1
hello,

In my strategy, I have an array of doubles, double[], that I would like to plot using PlotSeries() method or something equivalent on the ChartPane that I created. Can someone please help me to understand how, if possible, to convert an array of doubles to a DataSeries? Thanks

Max
profile picture

RA81

#2
hmm... each DataSeries Object has Data array with datetime type. So each value of DataSeries(DS) linked with time. If you want to make own DS object you You should be set all Times for each element.
Note that the data in the chart are based on the time/value. Your data has any relation to Time??
profile picture

Eugene

#3
Max,

If your double[] values correspond with the time axis (X), just create a new DataSeries and fill it using a simple for loop with the values.
profile picture

stolmax

#4
Eugune,

Thanks for responding. Do you mean I would just do this:

CODE:
Please log in to see this code.


Am I correct in interpreting your suggestion? Thanks in advance.

Max
profile picture

Eugene

#5
Yes.
profile picture

stolmax

#6
Thank you Eugene!!!
profile picture

aykuts

#7

Hi,

I checked the definition of the dataSeries as defined on the programming guide.

Accordingly, i tried to use .ToList() method, and managed successfully, to read the Dates as a list with the following code:
CODE:
Please log in to see this code.

Unfortunately, I cannot read the Close values with the same method: i.e. the following code doesnt work:
CODE:
Please log in to see this code.


I know (and it is already suggested as the solution within this thread) that I can fill my own List<double> with a loop.

But, I just wonder if there exists neater and faster ways of doing that instead of the loop, like that .ToList() method I can use for the Dates.

Thanks in advance!

Aykut Sarıbıyık

profile picture

Cone

#8
The DataSeries type does not have a ToList() method (nor a LINQ extension method), so you'll have to write the 2 or 3 lines of looping code to populate a List<>.
profile picture

Eugene

#9
Internally, everything boils down to looping so it's about "neater" but not "faster". Like Cone said, you need to write those lines of looping code. Then you can wrap them up in a convenient extension method (see below). To use the demo strategy...

...in WL 6.4 - 6.6: to support LINQ you need to add a reference to System.Core v4.0. In the Strategy Editor, click "References...", switch to "Other assemblies to reference...", click "Add a reference", find the file called System.Core.dll, highlight it and confirm. The file's placement depends on your OS and WLP "bitness". For 64-bit WLP, choose c:\windows\microsoft.net\framework64\v4.0.30319, for 32-bit WLP it's c:\windows\microsoft.net\framework\v4.0.30319.

...in WL 6.7, 6.8 (soon to be released), it's ready out of the box.

The idea is to take this "public static class DataSeriesEx", compile a DLL, and drop it in Wealth-Lab's main folder under Program Files. No need to have that class in your Strategies. [In 6.6 you may still need the System.Core.dll reference in your Strategy to be able to use "System.Linq" but WL 6.8 is almost at the door.] Then, .ToList() will become available to any DataSeries as an extension method. This is how many methods from Community Components now work, for example.

CODE:
Please log in to see this code.


EDIT

Or maybe it makes sense to add this .ToList method to C.Components.
profile picture

aykuts

#10
Great help.

Thanks once again.

Best regards

profile picture

Eugene

#11
fyi, .ToList() was added to C.Components in v2014.12.
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).