How can I access daily data in a weekly strategy? For example for my weekly strategy I want to enter only if the daily close of SPY is above its 200d sma. Thanks
Rename
Does ScaleInd work from weekly to daily? I thought it compresses timeseries so it could be used when one has a daily strategy but want to use weekly/monthly data. In my case I have a weekly strategy and want to use daily data of an external ticker. I tried it seems it did not generate any signal.
I think I got your point: use a daily strategy and scale all indicators I'm using on weekly using ScaleInd.
In the case of using a Weekly scale, you can simply use a Weekly SMA(42) to approximate the Daily SMA(200). The difference is negligible.
Just to compare, here's how you can do it in C# code, which shows how to access and synchronize daily data in a weekly scale (no block for that).
Run this on a Weekly scale, first with wper = 40 (200 / 5). With wper = 42, the plots are nearly identical.
Just to compare, here's how you can do it in C# code, which shows how to access and synchronize daily data in a weekly scale (no block for that).
Run this on a Weekly scale, first with wper = 40 (200 / 5). With wper = 42, the plots are nearly identical.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { TimeSeries _dailySMA; public override void Initialize(BarHistory bars) { BarHistory dailybars = GetHistoryUnsynched(bars.Symbol, HistoryScale.Daily, null); _dailySMA = SMA.Series(dailybars.Close, 200); // now synchronize to the chart scale _dailySMA = TimeSeriesSynchronizer.Synchronize(_dailySMA, bars); PlotTimeSeriesLine(_dailySMA, "Daily SMA(200)", "Price", WLColor.Red); // assuming weekliy bars, plot a weekly SMA(40) to compare. Using 42 to line up identically int wper = 40; PlotTimeSeriesLine(SMA.Series(bars.Close, wper), $"Weekly SMA({wper})", "Price", WLColor.Yellow); } public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { // entry logic if (bars.Close[idx] > _dailySMA[idx]) { } } else { } } } }
Thanks @Cone. Here you provided two ways to accomplish what I wanted in a weekly strategy:
1. load daily bars with GetHistoryUnsynced
2. Use weekly SMA to approximate daily SMA.
1. load daily bars with GetHistoryUnsynced
2. Use weekly SMA to approximate daily SMA.
Your Response
Post
Edit Post
Login is required