- ago
Hi,
What is the WL7 equivalent of the following WL6 code?
CODE:
foreach (string symbol in DataSetSymbols)
1
1,032
Solved
17 Replies

Reply

Bookmark

Sort
- ago
#1
Hi,

If it is the current DataSet your strategy is running on you can use BacktestData:
https://www.wealth-lab.com/Support/ApiReference/UserStrategyBase
1
- ago
#2
I didn't find how to get a single dataset, but I use this way of getting dataset and iterating over symbols:

CODE:
foreach (DataSet ds in DataSetFactory.DataSets) { BarHistory baseBars = GetHistoryUnsynched("IMOEX", HistoryScale.Daily, "d1_stocks_MOEX"); if (ds.Name == "d1_stocks_MOEX") { WriteToDebugLog(ds.Name); tickerBars = new BarHistory[ds.Symbols.Count]; int tickerCounter = 0; foreach (string ticker in ds.Symbols) { WriteToDebugLog(ticker); tickerBars[tickerCounter] = GetHistory(baseBars, ticker, ds.Name); tickerCounter++; } } }

0
- ago
#3
@Replikant_m

Nice suggestion. Here's how to find a single DataSet by name:

CODE:
var myDS = DataSetFactory.DataSets.Find(delegate (DataSet ds) { return ds.Name == "d1_stocks_MOEX"; });


@Sammy_G

To use this code by Replikant_m you have to add this to your strategy:

CODE:
using WealthLab.Data;
0
- ago
#4
A saw that "Find", but my C# wasn't enaugh for it)). Thanks.
0
Glitch8
 ( 10.62% )
- ago
#5
Or just use the handy Find method already provided in DataSetFactory.
0
Cone8
 ( 4.98% )
- ago
#6
We probably need to get these Factories in the QuickRef, because it's not easy to discover them even if you're searching for it.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; using WealthLab.Data;      /*** Add this ***/ namespace WealthScript5 { public class MyStrategy : UserStrategyBase { public override void BacktestBegin() {          DataSet ds = DataSetFactory.FindDataSet("Nasdaq 100");          foreach (string sym in ds.Symbols)          {             WriteToDebugLog(sym);          } } public override void Initialize(BarHistory bars) {        } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx)       {       } } }
2
- ago
#7
Thank you, all!

CODE:
DataSet ds = DataSetFactory.FindDataSet("Nasdaq 100");


How do I modify the above code if I want to use the *current* dataset?
0
- ago
#8
See Post #1.
0
- ago
#9
Got it, thanks!

A separate section in QuickRef on DataSets would be very useful.
0
Cone8
 ( 4.98% )
- ago
#10
DataSetFactory not required. We already have this documented in the QuickRef as an IHost method:

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript55 {    public class MyStrategy : UserStrategyBase    {       public override void BacktestBegin()       {          DataSet ds = WLHost.Instance.FindDataSet("Nasdaq 100");          foreach (string sym in ds.Symbols)          {             WriteToDebugLog(sym);          }       }       public override void Initialize(BarHistory bars)       {       }       //execute the strategy rules here, this is executed once for each bar in the backtest history       public override void Execute(BarHistory bars, int idx)       {       }    } }
2
Best Answer
- ago
#11
For Sammy_G's and others' reference. As looping through symbols has more applications than just rotation strategy, I've appended the discussion that followed here to another topic:

https://www.wealth-lab.com/Discussion/Converting-a-WL6-rotation-script-to-WL7-5613
0
- ago
#12
CODE:
DataSet ds = WLHost.Instance.FindDataSet("Nasdaq 100"); foreach (string sym in ds.Symbols) { WriteToDebugLog(sym); }

After retrieving the symbols how does one retrieve their bar histories?
0
- ago
#13
GetHistory, GetHistoryUnsynched
https://www.wealth-lab.com/Support/ApiReference/UserStrategyBase
0
- ago
#14
I had looked at that. While it's OK to access a symbol or two, or for external symbols, seems impractical to give a name to each BarHistory you want to create via symbol loop in a dataset.
0
- ago
#15
QUOTE:
to give a name to each BarHistory you want to create

I'm at a loss as to what this should mean.

Aside, that's the Flyweight design pattern was invented for in programming languages. To reduce the number of instances, an instance is created before the loop, properties are assigned etc.

CODE:
DataSet ds = WLHost.Instance.FindDataSet("Nasdaq 100"); //create object one BarHistory bh = ... foreach (string sym in ds.Symbols) { //do something on BarHistory bh... }
0
Glitch8
 ( 10.62% )
- ago
#16
This doesn't make sense, Sammy. Presumably, you'd be doing this in some kind of loop. So you would not need to create a named variable for each symbol in the DataSet. I'm not sure really what you're looking for here or how what is provided doesn't satisfy the need to obtain data from an external symbol.
0
- ago
#17
It's OK.
At my current level of WL7 knowledge I find Eugene's solution (Post #1) best & easiest to access symbols/BarHistory in current dataset. I also appreciate Cone's solutions to access symbols in any dataset.
:)
0

Reply

Bookmark

Sort