- ago
I am attempting to use a bit of code from a non-WL source and have a couple of questions.

The first is that the input to the code uses a List. How do I convert bars.Close to a List?

The second is that the code returns a List. How do I convert that to a TimeSeries?

Thanks!
0
110
Solved
4 Replies

Reply

Bookmark

Sort
Cone8
 ( 3.17% )
- ago
#1
CODE:
public override void Initialize(BarHistory bars) {          // 1.          List<double> closes = new(bars.Count);          for (int n = 0; n < bars.Count; n++)             closes.Add(bars.Close[n]);    }

A List<double> to a TimeSeries isn't possible without knowing the timestamps associated with each value.
0
- ago
#2
Thanks Cone!

QUOTE:
A List<double> to a TimeSeries isn't possible without knowing the timestamps associated with each value.


If the timestamps are identical to the input, can it be done then?
0
Cone8
 ( 3.17% )
- ago
#3
Assuming the List is synchronized with the BarHistory, then this should work -

CODE:
public override void Initialize(BarHistory bars) {          List<double> values = []; // some array of values                       // usage          TimeSeries mytimeseries = ListToTimeSeries(values, bars.Close);           }                     public TimeSeries ListToTimeSeries(List<double> values, TimeSeries sync)       {          if (values.Count != sync.Count)             throw new InvalidDataException("The list of values is not synchonized with the context.");                          TimeSeries ts = new TimeSeries(sync.DateTimes);          for (int n = 0; n < ts.Count; n++)             ts[n] = values[n];          return ts;       }
0
Best Answer
- ago
#4
Thanks Cone! I will check it out.
0

Reply

Bookmark

Sort