In WLD6 environment I use LoadFromFile extensively from class libraries outside the WealthLab environment.
I can't find the equivalent in WL7? I have experimented using GetHistoryUnsynched and the IHost interface but get the object reference not set exception.
Thanks
I can't find the equivalent in WL7? I have experimented using GetHistoryUnsynched and the IHost interface but get the object reference not set exception.
Thanks
Rename
It's not documented in the online API reference yet but there are WriteToBinaryFile and ReadFromBinaryFile which should solve the problem:
https://www.wealth-lab.com/Support/ApiReference/BarHistory
https://www.wealth-lab.com/Support/ApiReference/BarHistory
CODE:
public void WriteToBinaryFile(string fileName) public void ReadFromBinaryFile(string fileName, DateTime startDate, DateTime endDate, int maxBars)
Here's sample code to get you going:
CODE:
//create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { string path = @"c:\temp\aapl.qx"; BarHistory bh = GetHistoryUnsynched("AAPL", bars.Scale); bh.WriteToBinaryFile(path); BarHistory fromFile = new BarHistory(bars); fromFile.ReadFromBinaryFile(path, bars.DateTimes[0], bars.DateTimes[bars.DateTimes.Count -1], 0); PlotBarHistory(fromFile, "AAPL"); }
Great. Thank you
Note, you can also specify DateTime.MinValue and DateTime.MaxValue in the two date parameters to read all available data.
This is working well for me.
I used IQFeed.
2 additional points:
#1: When working outside of the WealthLab environment in my own application and Unit Test space I do not know the initial start date of the dataset before hand. I therefore do an initial read of the file, and this allows me to get FileBarCount
#2: Then in addition when using a weekly time scale then I need to post process with BarHistoryCompressor from the daily scale.
These are working for me today, but I'm hoping these might be optimized perhaps in the distant future.
I used IQFeed.
2 additional points:
#1: When working outside of the WealthLab environment in my own application and Unit Test space I do not know the initial start date of the dataset before hand. I therefore do an initial read of the file, and this allows me to get FileBarCount
CODE:
public BarHistory LoadAllDataFromFile(string symbol, HistoryScale scale) { var fileBars = new BarHistory("NewBars", scale); var path = GetSymbolPath(symbol, scale); var startDate = DateTime.Now.AddDays(-7); var endDate = DateTime.Now; var maxBars = GetMaxBars(scale, startDate, endDate); fileBars.ReadFromBinaryFile(path, startDate, endDate, maxBars); startDate = DateTime.Now.AddDays(fileBars.FileBarCount * -2); maxBars = GetMaxBars(scale, startDate, endDate); var bars = new BarHistory("NewBars", scale); bars.ReadFromBinaryFile(path, startDate, endDate, maxBars); return scale == HistoryScale.Weekly ? BarHistoryCompressor.ToWeekly(bars) : bars; } private static int GetMaxBars(HistoryScale scale, DateTime startDate, DateTime endDate) { if (scale == HistoryScale.Weekly) return (int)(endDate.Date - startDate.Date).TotalDays; if (scale == HistoryScale.Daily) return (int)(endDate.Date - startDate.Date).TotalDays; if (scale == HistoryScale.Minute30) return (int)(endDate - startDate).TotalMinutes; if (scale == HistoryScale.Minute5) return (int)(endDate - startDate).TotalMinutes; if (scale == HistoryScale.Minute1) return (int)(endDate - startDate).TotalMinutes; throw new ArgumentException("Timescale invalid"); }
#2: Then in addition when using a weekly time scale then I need to post process with BarHistoryCompressor from the daily scale.
These are working for me today, but I'm hoping these might be optimized perhaps in the distant future.
Your Response
Post
Edit Post
Login is required