1 registered members (AndrewAMD),
1,306
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Mixed frequency history (M1+D)
[Re: jcl]
#477207
05/31/19 13:01
05/31/19 13:01
|
Joined: Apr 2019
Posts: 20
kankan
OP
Newbie
|
OP
Newbie
Joined: Apr 2019
Posts: 20
|
So I assembled the history in UTC, single file per asset, that has a mix of daily and 1-minute bars, with the timestamp at the end of the bar as written in the manual. I've been reading about it and I am still very confused on how to set up the script to make use of this data. With the below setup, I get " SMA Lookback period exceeded by 286360 bars" error. I am guessing it's expecting 200*1440 minute bars before the StartDate. Do I need to make my own bar() function to make use of this data properly? The data is stored like this. I don't need empty bars where there is no data, correct? 2018.07.31 13:33 190.02 190.31 189.95 190.21 0 834 // MINUTE 2018.07.31 13:32 190.31 190.34 189.91 190 0 1233 // MINUTE 2018.07.31 13:31 190.34 190.5 190 190.3 0 4165 //MINUTE 2018.07.30 20:00 191.98 192.2 189.07 189.91 0 1.59208E+07 //DAILY 2018.07.27 20:00 194.93 195.19 190.21 190.98 0 1.41448E+07 //DAILY 2018.07.26 20:00 194.61 195.96 193.61 194.21 0 1.43066E+07 //DAILY The assets file first has a DUMMY asset, then another entry for AAPL The very basic script where I am opening a long trade on a specific date that has daily resolution data:
function run() {
BarPeriod = 1;
StartDate = 20130301;
LookBack = 200*1440; // enough for the 200day SMA
LifeTime = 448; // automatically close trades at the end of the day
assetList("History\AssetsEarnings.csv");
History = "m.t6";
asset(""); // not sure if I need the DUMMY here...
asset("AAPL");
TimeFrame = 1440; // daily SMA
vars dailyPrices = series(priceClose());
vars smaDaily = series(SMA(dailyPrices, 200));
// buy after open on 2018-07-31... the day that has minute resolution data
if(year(0)==2018 && month(0)==7 && day(0)==31) {
TimeFrame = 1; // run on minute intervals during trading
if(ltod(ET, 0)==931 && NumOpenLong == 0) {
enterLong();
}
}
else {
TimeFrame = 1440;
}
|
|
|
Re: Mixed frequency history (M1+D)
[Re: Petra]
#477221
06/01/19 12:42
06/01/19 12:42
|
Joined: Apr 2019
Posts: 20
kankan
OP
Newbie
|
OP
Newbie
Joined: Apr 2019
Posts: 20
|
Thank you Petra. To play with it, I removed the SMA calculation and then things run as expected.
However, I am still confused with what a Bar really refers to (and therefore BarPeriod). I thought it was a time interval, say 1-minute, and regardless of the gaps in the history I have, it will be a fixed number of them between StartDate and EndDate.
But, it seems that it refers to the actual historical bars, more like candles actually. Is this correct? So in my case, a daily candle (when there are no minute candles), is treated as 1 bar, much the same as an intraday 1-minute candle. Therefore, when I set Lookback to 200, that can refer to a varying amount of time actually, depending on the available history before the StartDate?
Am I understanding this correctly?
Also, I am unsure what you mean by "calculate sma by script". Do you mean I manually have to build a series of just daily prices?
|
|
|
Re: Mixed frequency history (M1+D)
[Re: Petra]
#477230
06/03/19 16:49
06/03/19 16:49
|
Joined: Apr 2019
Posts: 20
kankan
OP
Newbie
|
OP
Newbie
Joined: Apr 2019
Posts: 20
|
This is how I managed to build a daily SMA, however this seems extremely fragile to me (for backtesting). For example, if there were no trades at 16h ET, there would be no bar and we wouldn't produce a daily close. There must be a more robust way of doing this, no? Is there some way to track an internal clock during backtesting?
// capture NYSE market close and the Friday close that falls on Sunday 23h UTC
static int numSkippedBars = 0;
if(lhour(ET, 0)==16 || hour(0)==23) {
TimeFrame = min(-1, -numSkippedBars);
numSkippedBars = 0;
}
else {
TimeFrame = 0;
numSkippedBars++;
}
vars dailyPrices = series(priceClose(0));
vars sma = series(SMA(dailyPrices, 200));
I also tried this, but it doesn't work correctly and I'm not sure why. It correctly gets the daily close when there are intraday bars and on the first day of the week only. Everything else gets skipped (TimeFrame=0). Why?
FrameOffset = 21*60-dst(ET, 0)*60;
TimeFrame = frameSync(1440);
vars dailyPrices = series(priceClose(0));
vars sma = series(SMA(dailyPrices, 200));
What would be a proper way to build a daily close series? Thank you.
|
|
|
|