I have a intra day strategy am trying to implement but the entry is based on rules in daily time frame. Example: Buy intraday bar if current price is above avg MA (20) on daily scale. Is there a sample C# code i can add to my current code to apply that additional criteria based on "daily" time frame? Thanks in advance!
Rename
Yes, it's TimeSeriesCompressor:
https://www.wealth-lab.com/Discussion/GetHistory-for-daily-symbol-from-within-an-intraday-strategy-6756
https://www.wealth-lab.com/Discussion/GetHistory-for-daily-symbol-from-within-an-intraday-strategy-6756
Here's a minimal example that will generate and plot a daily SMA on intraday data:
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { //Initialize public override void Initialize(BarHistory bars) { //get daily SMA dailyClose = TimeSeriesCompressor.ToDaily(bars.Close); dailySMA = SMA.Series(dailyClose, 4); //expand it back to intraday time frame dailySMA = TimeSeriesSynchronizer.Synchronize(dailySMA, bars); //plot it PlotTimeSeries(dailySMA, "Daily SMA(4)", "Price", Color.Navy); } //Execute public override void Execute(BarHistory bars, int idx) { } //private members private TimeSeries dailyClose; private TimeSeries dailySMA; } }
The sample code in the "Initialize" section was helpful and i was able to get it to work and plot the daily MA(20) on the intraday scale. Also re-synched it to the intraday scale. I also declared the MA(20) variable "ma20" in the private members as a TimeSeries. For some reason, the code below in the "Execute" section of the code compiles without and error but when i backtest using the code it is throwing an error (image uploaded)
if (indicator1[index] < ma20[index])
{
//buy
}
if (indicator1[index] < ma20[index])
{
//buy
}
Somehow one of the variables was not initialized, if you post the full code we can help.
I recently incorporated an HV indicator in my options trading strategy that uses 30 min data. To test the accuracy of the indicator, I ran a separate test program that uses daily data. I am not getting the exact same results (to 2 decimal places) with the intraday compressed bars as the daily test. Should I expect to?
HV DAILY BARS TEST
HV INTRADAY BARS TEST
HV DAILY BARS TEST
CODE:
public override void Initialize(BarHistory bars) { hv = HVbars.Close,60,252); PlotIndicator(hv); }
HV INTRADAY BARS TEST
CODE:
_dailyBars = BarHistoryCompressor.ToDaily(bars); _dailyBarsSynced = BarHistorySynchronizer.Synchronize(_dailyBars, bars); _dailySeries = _dailyBars.Close; _hvSeries = HV.Series(_dailySeries, 60, 232); _dailyHVSeries = TimeSeriesSynchronizer.Synchronize(_hvSeries, bars.Close); PlotTimeSeries(_dailyHVSeries, "HV", "HV Value", WLColor.Orange);
No, because the last-trade (intraday) close is often different than the Daily settled closing price.
If it's that important to use Daily settled closing prices, instead of compressing, grab the Daily bars using WLHost.Instance.GetHistory(bars.Symbol, HistoryScale.Daily, ...
If it's that important to use Daily settled closing prices, instead of compressing, grab the Daily bars using WLHost.Instance.GetHistory(bars.Symbol, HistoryScale.Daily, ...
OK. Made the change. Thanks for the suggestion.
I have to synchronize the daily history with intraday bars so it will run properly in the Execute method (in addition to plotting properly). Sort of a "decompress."
I have to synchronize the daily history with intraday bars so it will run properly in the Execute method (in addition to plotting properly). Sort of a "decompress."
Right, you still have to synchronize in some way.
Using BarHistorySynchronizer() is easiest.
Using BarHistorySynchronizer() is easiest.
Can we do this indicator shift/compression from intraday to eod also with building blocks too? for example: entry on n bars low (based on 5 minutes) wenn daily rsi is less than 45?
We have the ScaleInd indicator for this purpose.
Your Response
Post
Edit Post
Login is required