Create new graph in weekly timeframe

@cecil If you simply want to show a weekly chart, all you need is to change the active symbol interval:

immagine

On the other hand, the use of TimeFrameSet() / TimeFrameRestore() / TimeFrameExpand() is useful when on a single chart you want to plot values (or do some calculations) based on 2 or more timeframes (or more in general, the main use for timeframe functions is when you want to create some trading rules based on MULTIPLE time frames at once).

To learn more, please, read this part of the documentation: Multiple Time Frame support in AFL.
In particular, I suggest studying/plotting the Examples and also to execute the exploration code (located just before the example section), that is very useful to show what happens after you switch to a higher timeframe.

Anyway, here is a basic example of a chart (to be displayed setting a Daily interval using daily data) that uses the timeframe functions to plot some lines at the weekly and monthly High and Low levels.

TimeFrameSet(inWeekly);
L_w = L;
H_w = H;
TimeFrameRestore();
TimeFrameSet(inMonthly);
L_m = L;
H_m = H;
TimeFrameRestore();

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - " +FullName() + " - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +
   WriteVal( V, 1.0 ) +"\n{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

Plot(C, "Close", colorDefault, styleCandle);

Plot( TimeFrameExpand(H_w, inWeekly), "H. Wk", colorRed, styleLine | styleThick);
Plot( TimeFrameExpand(L_w, inWeekly), "L. Wk", colorGreen, styleLine | styleThick);
Plot( TimeFrameExpand(H_m, inMonthly), "H. Mo", colorDarkRed, styleDashed | styleThick);
Plot( TimeFrameExpand(L_m, inMonthly), "L. Mo", colorDarkGreen, styleDashed | styleThick);

immagine



IMPORATANT: when you post some code example you should always use the required code tags as clearly explained in the section Enter the AFL code properly of the How to use this site thread.