I want to use the daily close of another symbol in a backtest of an intraday symbol. The doc is not specific about how to do that. I tried
with and without the MarketDetails part, but there is always the error message:
Could not load Backtest Data in this Scale/Range
I imagine it could be helpful to add an example regarding this into the doc.
CODE:
BarHistory term = GetHistory(bars, _term); term_close = term.Close; MarketDetailsUsaStocks md = new MarketDetailsUsaStocks(); md.GetCloseTimeMarketTime(); daily_term = TimeSeriesSynchronizer.Synchronize(term_close, bars, null, md);
with and without the MarketDetails part, but there is always the error message:
Could not load Backtest Data in this Scale/Range
I imagine it could be helpful to add an example regarding this into the doc.
Rename
Probably your error comes from not having intraday data for the _term symbol. The script attempt to access it in the scale of the primary BarHistory.
There are at least 3 ways to do this, but in a C# Coded Strategy, the WLHost GetHistory call for Daily bars and then synchronizing is the way to go, imho.
There are at least 3 ways to do this, but in a C# Coded Strategy, the WLHost GetHistory call for Daily bars and then synchronizing is the way to go, imho.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript7 { public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { _dailySync = WLHost.Instance.GetHistory(_term, HistoryScale.Daily, DateTime.MinValue, DateTime.MaxValue, 0, null); _sma200 = SMA.Series(_dailySync.Close, 200); //synchronize to intraday chart _dailySync = BarHistorySynchronizer.Synchronize(_dailySync, bars); _sma200 = TimeSeriesSynchronizer.Synchronize(_sma200, bars); //plotting PlotTimeSeriesLine(_dailySync.Close, _term + " Daily Close", "Price"); PlotTimeSeriesLine(_sma200, _term + " Daily SMA(200)", "Price"); } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } } //declare private variables below BarHistory _dailySync; TimeSeries _sma200; string _term = "QQQ"; } }
Thx for the quick feedback and the suggestion, but the very first line still gives the error (I tried it with ASCII data wo intraday data as well as with iqfeed data)
CODE:
_term_series = WLHost.Instance.GetHistory(_term, HistoryScale.Daily, DateTime.MinValue, DateTime.MaxValue, 0 , null);
Show a complete, minimal example. Then maybe we can help further.
I created a minimal example... and it worked.
Then I tried to adjust the original code and after a while it worked also. Not totally sure what the problem was, but obviously something on my side. Sorry about that, and many thanks for your solution.
Then I tried to adjust the original code and after a while it worked also. Not totally sure what the problem was, but obviously something on my side. Sorry about that, and many thanks for your solution.
fwiw, here's another way using the Transformer indicators. The only difference is that this will give you the daily Close series as an "IndicatorBase".
CODE:But I still prefer the other method, which allows creating long-period indicators that are valid on the first bar.
string _term = "QQQ"; // Another way IndicatorBase _dailyClose = ScaledInd.Series(bars, SymbolData.Series(bars, _term, PriceComponent.Close), HistoryScale.Daily); //plotting PlotTimeSeriesLine(_dailyClose, _term + " Daily Close", "Price", WLColor.Gold);
ok, thank you for the additional information
Your Response
Post
Edit Post
Login is required