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!
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!
Rename
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.
Thanks Cone!
If the timestamps are identical to the input, can it be done then?
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?
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; }
Thanks Cone! I will check it out.
Your Response
Post
Edit Post
Login is required