Timeframe setup

Hy there,

I would appreciate if someone can help me with the following TimeFrame issue. I already read “ Multiple time Frame support “ , “ time compression of data Retrieved from another symbol”, the Time frame related formulas and Tedbundy book.

The problem I have is that when I Set Timeframe (in weekly) and expand the Compressed array to use it in the Chart, or the exploration or the system code , the value of the array compressed in the dayly periodicity does not match the value of the array in the weekly periodicity.

I did the check with the following code.

_SECTION_BEGIN("RSC Mansfield FIJO EXPANDED");

TimeFrameSet(inWeekly);

//creado por Mansfield LTD y modificado por JA en 2010
//calculo de RSC Mansfield en comparacion con S&P500
period=52;
Cociente=C/Foreign("^GSPC","C");
CountR=Sum(Cociente,period);
Baseprice=CountR/period;
RSC=((Cociente/Baseprice)-1)*10;

TimeFrameRestore();

RSCweek=TimeFrameExpand(RSC,inWeekly,expandLast);

//escogemos la forma de representacion y estilos
SetGradientFill(colorGreen/*top*/,colorRed/*bottom*/,0/*baseline level*/,GetChartBkColor()/*baseline color*/);
//mostramos en pantalla la variable RSC que contiene el RSC de Mansfield
Plot(RSCweek,"RSCMansfield vs S&P500---FIJO SEMANAL EXpanded", colorLightOrange, styleLine | styleGradient);
_SECTION_END();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
_SECTION_BEGIN("RSC Mansfield FIJO");

TimeFrameSet(inWeekly);

//creado por Mansfield LTD y modificado por JA en 2010
//calculo de RSC Mansfield en comparacion con S&P500
period=52;
Cociente=C/Foreign("^GSPC","C");
CountR=Sum(Cociente,period);
Baseprice=CountR/period;
RSCweeknot=((Cociente/Baseprice)-1)*10;

TimeFrameRestore();


//escogemos la forma de representacion y estilos
SetGradientFill(colorGreen/*top*/,colorRed/*bottom*/,0/*baseline level*/,GetChartBkColor()/*baseline color*/);
//mostramos en pantalla la variable RSC que contiene el RSC de Mansfield
Plot(RSCweeknot,"RSCMansfield vs S&P500---FIJO SEMANAL ", colorLightOrange, styleLine | styleGradient);
_SECTION_END();

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
_SECTION_BEGIN("RSC Mansfield normal");



//creado por Mansfield LTD y modificado por JA en 2010
//calculo de RSC Mansfield en comparacion con S&P500
period=Param("Periodo",52,1,500,1);
rsSymbol=ParamStr("Base Index Symbol","^GSPC");
Cociente=C/Foreign(rsSymbol,"C");
CountR=Sum(Cociente,period);
Baseprice=CountR/period;
RSCnormal=((Cociente/Baseprice)-1)*10;




//escogemos la forma de representacion y estilos
SetGradientFill(colorGreen/*top*/,colorRed/*bottom*/,0/*baseline level*/,GetChartBkColor()/*baseline color*/);
//mostramos en pantalla la variable RSC que contiene el RSC de Mansfield
Plot(RSCnormal,"RSCMansfield vs S&P500---FIJO SEMANAL ", colorLightOrange, styleLine | styleGradient);
_SECTION_END();


Filter=1;
AddColumn(RSCweek,"RSCWeekExpanded",1.2);
AddColumn(RSCweekNot,"RSCWeekNotExpanded",1.2);
AddColumn(RSCnormal,"RSC",1.2);
AddColumn(DayOfWeek(),"DayOfWeek",1.2);

As yo can see in the code there are three indicators. The three are calculated the same way but:

In one of them I expanded the compressed array

In the other one I did not expand the compressed array

And in the third one I did not use the timeframe set function.

Then I apply the exploration in weekly periodicity to a symbol( in this case Argenx).

As a result the Three indicators gave me the same value, which is ok and is what I expected.

image

However when I apply the exploration in a daily Peridicity I see the following:

image

I am not worried about the Not expanded data column because I know is wrong( I do not know what is computing but I do not care) . the column labeled RSC is doing it right , the problem is the column with the expended array.

The values for the day 26/06 , 29/06 to 02/07 should be the values that the exploration run on the weekly peridicty for the week of 26/06 ; thus should be 5,01 instead of 4,89. It looks like if the compressed value is not properly computed.

However I do the same exercise with the code or a Simple moving average of 3, and everything matches and looks OK.

Any idea or Help. Please

This has been posted several times in forum already.
Do not use Foreign within Timeframeset.

First and formost... there is also Knowledgebase Article
https://www.amibroker.com/kb/2014/10/20/foreign-timeframeset/
As newbie entire AmiBroker KB is mandatory read before coming to forum.

Compress Foreign symbol before and then use it in TimeFrameSet with selected symbol's array for further calculation(s)

_SECTION_BEGIN("RSC Mansfield FIJO EXPANDED");
period=52;

spx = Foreign("^GSPC","C");
spx_weekly = TimeFrameCompress(spx, inWeekly);

TimeFrameSet(inWeekly);

//creado por Mansfield LTD y modificado por JA en 2010
//calculo de RSC Mansfield en comparacion con S&P500
Cociente=C/spx_weekly;
CountR=Sum(Cociente,period);
Baseprice=CountR/period;
RSC=((Cociente/Baseprice)-1)*10;

TimeFrameRestore();

RSCweek=TimeFrameExpand(RSC,inWeekly,expandLast);

//escogemos la forma de representacion y estilos
SetGradientFill(colorGreen/*top*/,colorRed/*bottom*/,0/*baseline level*/,GetChartBkColor()/*baseline color*/);
//mostramos en pantalla la variable RSC que contiene el RSC de Mansfield
Plot(RSCweek,"RSCMansfield vs S&P500---FIJO SEMANAL EXpanded", colorLightOrange, styleLine | styleGradient);
_SECTION_END();

Filter=1;
AddColumn(RSCweek,"RSCWeekExpanded",1.2);
AddColumn(DayOfWeek(),"DayOfWeek",1.2);

You should always expand.

Thanks a lot for your help. I appreciate it.

I am a newbie AMibroker of course, but I must say that I read the article you mention and some others. None of them say that you can not use TimeFrame set with foreing or setforeign. I made the effort before asking.

Anyway, thanks for your help.

Best

I did not write that you can not use SetForeign. I wrote that you should not use foreign (functions) within Timeframeset (procedure):

"Within" means to not call foreign functions after TimeFrameSet() and before TimeFrameRestore().

Also the article has clear (code) guideline(s) to call SetForeign before TimeFrameSet.
Also that article shows (via presenting sample code) that if using Foreign() then call it before TimeFrameCompress.
Also as you can see in my upper post I use Foreign before TimeFrameSet and before TimeFrameCompress (so following the guidelines). Foreign() function internally sets to foreign symbol's price array and restores to original price array in one go. And you did all that after setting to other time frame (via TimeFrameSet) which that article never proposes to do anywhere in there (code examples with comments are documentation too). So it is clear why you get undesired results when you do as you did in first post.

I apologize, my mistake.

Thanks again for your time and effort to clarify for me.

Best regards

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.