function run(){
BarPeriod = 1;
LookBack = 240*100;
StartDate = 20100101;
EndDate = 20100201;
set(NOSHIFT); //shift manually
asset("EURUSD");
vars priceM1 = series();
vars priceM5 = series();
if (is(INITRUN)){
priceM1 = series(0, 100);
priceM5 = series(0, 100);
}
TimeFrame = 1;
shift(priceM1, priceClose(), 100);
TimeFrame = 5;
if (frame(0)) shift(priceM5, priceClose(), 100);
if (!is(LOOKBACK)){
int i, j;
for (i=0; i<10; i++){
printf("\n--- M5: %.5f", priceM5[i]);
for (j=0; j<5; j++){
printf("\n M1: %.5f", priceM1[i*5+j]);
}
}
quit(0);
}
}
I attached the results. How is it possible that the M1 middle candle is determining the closing price of the M5 candle? Shouldn't it be the last one? The expected result are the following:
I did the custom shifting because the automatic shifting (as suggested in the example codes in TimeFrame help) did exactly the same. And because I did not understand why it does, I tried to "implement", but same results. So the following code, the automatic shifting acts just exactly the previously posted:
Code
function run(){
BarPeriod = 1;
LookBack = 240*100;
StartDate = 20100101;
EndDate = 20100201;
asset("EURUSD");
TimeFrame = 1;
vars priceM1 = series(priceClose(), 100);
TimeFrame = 5;
vars priceM5 = series(priceClose(), 100);
if (!is(LOOKBACK)){
int i, j;
for (i=0; i<10; i++){
printf("\n--- M5: %.5f", priceM5[i]);
for (j=0; j<5; j++){
printf("\n M1: %.5f", priceM1[i*5+j]);
}
}
quit(0);
}
}
Last edited by NorbertSz; 09/06/2218:23.
Re: Series, shifting and timeframes
[Re: NorbertSz]
#486576 09/06/2220:0009/06/2220:00
The results are the expected: the last M1 candle closePrice() is the same that M5 candle closePrice(), as seen in the first attachment of this post. Now I understand that if the LookBack finishes not exactly in TimeFrame 5 frame(0) then the whole M1 series will be shifted, because it got new elements but the M5 series did not. Attachment.
One possible solution for printing is shifting the data inside the series:
Code
function run(){
BarPeriod = 1;
LookBack = 240*100;
StartDate = 20100101;
EndDate = 20100201;
asset("EURUSD");
TimeFrame = 1;
vars priceM1 = series(priceClose(), 100);
//printf("\nM1: %.5f", priceClose());
TimeFrame = 5;
vars priceM5 = series(priceClose(), 100);
//if (frame(0)) printf("\n --- M5: %.5f", priceClose());
if (!is(LOOKBACK)){
//shift some data
int i, j, shift;
TimeFrame = 5;
for (i=0; i<4; i++){
if (frame(i)) shift = i + 1;
}
//print
for (i=0; i<10; i++){
printf("\n--- M5: %.5f", priceM5[i]);
for (j=0; j<5; j++){
printf("\n M1: %.5f", priceM1[shift + i*5 + j]);
}
}
quit(0);
}
}