Code Question 2:
CODE:
DataSourceManager dm = new WealthLab.DataSourceManager(); dm.RootPath = Application.UserAppDataPath + @"\Data"; foreach (DataSource ds in dm.DataSources) { PrintDebug(ds.Name); foreach (string sym in ds.Symbols) { Bars b = GetExternalSymbol(sym, true); Bars y = BarScaleConverter.ToYearly(b); y = Synchronize(y); } }
Rename
First of all let's find out why you think you need to loop by DataSets as in WL6 i.e. what's your objective?
Thanks Eugene.
The simple use case is to calculate the ROC of several datasets.
The simple use case is to calculate the ROC of several datasets.
That would be a suboptimal way to achieve it. How about the CompInd indicator from IndexLab that does it via drag& drop?
IndexLab - Create composite indicators based on any DataSet
* CompInd - Select any Wealth-Lab indicator, returns the average indicator value across the Universe
IndexLab - Create composite indicators based on any DataSet
* CompInd - Select any Wealth-Lab indicator, returns the average indicator value across the Universe
Eugene's correct, but just in case you want to accomplish this, in Build 2 we've introduced a way to specify the DataSet name in a call to GetHistory or GetHistoryUnsynched. So, once we release Build 2 you'll be able to do this. Note I stopped this after 6 DataSets because I have so many and I didn't want it to keep running :)
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; using WealthLab.Data; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { public override void BacktestBegin() { int n = 0; foreach (DataSet ds in DataSetFactory.Instance.CustomDataSets) { WriteToDebugLog("DataSet: " + ds.Name); foreach (string symbol in ds.Symbols) { BarHistory bh = GetHistoryUnsynched(symbol, HistoryScale.Daily, ds.Name); if (bh != null) { double roc = ROC.Value(bh.Count - 1, bh.Close, 20); WriteToDebugLog(symbol + ": " + roc.ToString("N2")); } } WriteToDebugLog(""); n++; if (n > 5) break; } } //Initialize public override void Initialize(BarHistory bars) { } //Execute public override void Execute(BarHistory bars, int idx) { } //private members } }
How would you determine and loop thru the current dataset only?
Why is this required?
WL7 is already doing that for you! It loops through the current DataSet and calls Initialize once for each symbol.
A simple example is that I have a script in WLD 6 that goes thru my portfolio, prepares data for each stock and provides me with a nice summary report.
See the example in the QuickRef for UserStrategyBase > Cleanup. WriteToDebugLog in this method will separate the output by symbol.
If you want to loop yourself so that all the WriteToDebugLog output is put together (for a table-like format), you can do it like this -
If you want to loop yourself so that all the WriteToDebugLog output is put together (for a table-like format), you can do it like this -
CODE:
public override void BacktestComplete() { foreach (BarHistory bh in BacktestData) { // do your thing here } }
Yes, there are work arounds but they require more work to develop and usually multi-steps to executed. I have found a lot of power in the ability to loop thru the stocks in a list and found it to be very powerful. I certainly would like to see it added to WL 7.
Did you read Cone’s reply immediately above yours? This isn’t a workaround this how you do it. Not sure how we could make this much simpler?? 🤷🏼♂️
I tried to run Glitch's strategy above and received the following error:
16: An object reference is required for the non-static field, method, or property 'DataSetFactory.CustomDataSets'
How do I correct this?
16: An object reference is required for the non-static field, method, or property 'DataSetFactory.CustomDataSets'
How do I correct this?
The factory classes have changed in Wl8. Use DataSetFactory.Instance.CustomDataSets.
Updated the code by Glitch in Post #4.
Thanks Glitch.
Your Response
Post
Edit Post
Login is required