Create new graph in weekly timeframe

I use this code but it doesn't work.
Please help me check it.


C_week = C;
H_week = H;
L_week = L;
O_week = O;
V_week = V;


_N(Title = StrFormat("{{NAME}} - Open %g, High %g, Low %g, Close %g (%.1f%%) Vol " +WriteVal( TimeFrameExpand(V_week, inWeekly), 1.0 ) +" {{VALUES}}", TimeFrameExpand(O_week, inWeekly), TimeFrameExpand(H_week, inWeekly), TimeFrameExpand(L_week, inWeekly), TimeFrameExpand(C_week, inWeekly), SelectedValue( ROC( TimeFrameExpand(C_week, inWeekly), 1 )) ));
SetChartBkColor(ParamColor("Outer panel",colorBlack));
SetChartBkGradientFill( ParamColor("Inner panel upper",colorBlack),ParamColor("Inner panel lower",colorBlack));
Plot( TimeFrameExpand(C_week, inWeekly), "Close", ParamColor( "Color", colorWhite ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );

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


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.

L_w = L;
H_w = H;
L_m = L;
H_m = H;

_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);


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.