- ago
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); } }
1
1,626
Solved
15 Replies

Reply

Bookmark

Sort
- ago
#1
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?
0
- ago
#2
Thanks Eugene.
The simple use case is to calculate the ROC of several datasets.
0
- ago
#3
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

0
Glitch8
 ( 10.62% )
- ago
#4
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 } }
0
Best Answer
- ago
#5
How would you determine and loop thru the current dataset only?
0
- ago
#6
Why is this required?
0
Glitch8
 ( 10.62% )
- ago
#7
WL7 is already doing that for you! It loops through the current DataSet and calls Initialize once for each symbol.
0
- ago
#8
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.
0
Cone8
 ( 4.98% )
- ago
#9
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 -

CODE:
public override void BacktestComplete() {          foreach (BarHistory bh in BacktestData)          {             // do your thing here          } }
1
- ago
#10
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.
0
Glitch8
 ( 10.62% )
- ago
#11
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?? 🤷🏼‍♂️
0
- ago
#12
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?
0
Glitch8
 ( 10.62% )
- ago
#13
The factory classes have changed in Wl8. Use DataSetFactory.Instance.CustomDataSets.
0
- ago
#14
Updated the code by Glitch in Post #4.
0
- ago
#15
Thanks Glitch.
0

Reply

Bookmark

Sort