- ago
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!
0
919
Solved
10 Replies

Reply

Bookmark

Sort
- ago
#1
Yes, it's TimeSeriesCompressor:

https://www.wealth-lab.com/Discussion/GetHistory-for-daily-symbol-from-within-an-intraday-strategy-6756
2
Best Answer
Glitch8
 ( 10.92% )
- ago
#2
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; } }
1
- ago
#3
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
}
0
Glitch8
 ( 10.92% )
- ago
#4
Somehow one of the variables was not initialized, if you post the full code we can help.
0
- ago
#5
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
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);
0
Cone8
 ( 23.78% )
- ago
#6
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, ...
0
- ago
#7
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."
0
Cone8
 ( 23.78% )
- ago
#8
Right, you still have to synchronize in some way.
Using BarHistorySynchronizer() is easiest.
0
- ago
#9
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?
0
Glitch8
 ( 10.92% )
- ago
#10
We have the ScaleInd indicator for this purpose.
0

Reply

Bookmark

Sort