Hi,
What is the WL7 equivalent of the following WL6 code?
What is the WL7 equivalent of the following WL6 code?
CODE:
foreach (string symbol in DataSetSymbols)
Rename
Hi,
If it is the current DataSet your strategy is running on you can use BacktestData:
https://www.wealth-lab.com/Support/ApiReference/UserStrategyBase
If it is the current DataSet your strategy is running on you can use BacktestData:
https://www.wealth-lab.com/Support/ApiReference/UserStrategyBase
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++; } } }
@Replikant_m
Nice suggestion. Here's how to find a single DataSet by name:
@Sammy_G
To use this code by Replikant_m you have to add this to your strategy:
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;
A saw that "Find", but my C# wasn't enaugh for it)). Thanks.
Or just use the handy Find method already provided in DataSetFactory.
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) { } } }
Thank you, all!
How do I modify the above code if I want to use the *current* dataset?
CODE:
DataSet ds = DataSetFactory.FindDataSet("Nasdaq 100");
How do I modify the above code if I want to use the *current* dataset?
See Post #1.
Got it, thanks!
A separate section in QuickRef on DataSets would be very useful.
A separate section in QuickRef on DataSets would be very useful.
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) { } } }
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
https://www.wealth-lab.com/Discussion/Converting-a-WL6-rotation-script-to-WL7-5613
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?
GetHistory, GetHistoryUnsynched
https://www.wealth-lab.com/Support/ApiReference/UserStrategyBase
https://www.wealth-lab.com/Support/ApiReference/UserStrategyBase
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.
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... }
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.
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.
:)
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.
:)
Your Response
Post
Edit Post
Login is required