TimeFrameSet with monthly data (Unemployment rate)

I downloaded the US unemployment rate (UNRATE) from the FRED website.

I would like to plot its EMA using TimeFrameSet , under a chart with the daily price of $SPX (Norgate data).

I was able to do it using TimeFrameCompress but not using TimeFrameSet and TimeFrameRestore() function. I have carrefully read the "Multiple Time Frame support in AFL webpage" without finding my error.

Why does it work if I select $SPX and a monthly period and doesn't work if I select $SPX and a daily period?

// This script create a wrong indicator, given in the image right below:
U3 = Foreign("U3_US_FRED","C");
U3_M = U3;
U3_M_EMA = EMA (U3_M,3);

//Plot(U3,"U3 From foreign", colorBlack, styleLine);
Plot(TimeFrameExpand( U3_M, inMonthly, expandLast), "U3 from Timeframeset", colorBlue, styleLine );
Plot(TimeFrameExpand( U3_M_EMA, inMonthly, expandLast), "U3 EMA from Timeframeset", colorGreen, styleLine);

// What is working:
U3 = Foreign("U3_US_FRED","C");
U3_M = TimeFrameCompress( U3, inMonthly, compressOpen );
U3_M_EMA = EMA (U3_M,3);
U3_M = TimeFrameExpand( U3_M, inMonthly, expandLast );
U3_M_EMA = TimeFrameExpand( U3_M_EMA, inMonthly, expandLast );

Plot(U3_M,"U3 From TimeFrameCompress", colorBlue, styleLine);
//Plot(U3,"U3 From foreign", colorBlack, styleLine);
Plot(U3_M_EMA,"U3 EMA From TimeFrameCompress", colorGreen, styleLine);

From the manual

The TimeFrameSet replaces CURRENT price/volume arrays: open, high, low, close, volume, openint, avg with time-compressed bars of specified interval

in other words , when you use Foreign "inside" it, the variable you assigned is not changed

You need to set the symbol before you use TimeFrameSet

See SetForeign function

1 Like

It is still not working :confused:
The error in the indicator plotted in the image doesn't come from here.
In my personnal code, SetForeign was before TimeFrameSet.
I put it here because I thought it would be easier to read (sorry!)...

TimeFrameSet does NOT affect anything but built-in OHLC arrays.
So only those OHLC arrays and functions like RSI, CCI, MFI, etc, using built-in OHLC arrays (current symbol) would use compressed timeframe.

Foreign does not use current symbol OHLC arrays.
In your code Foreign returns UNCOMPRESSED array (in original time frame).

If you want to use Foreign you have to use TimeFrameCompress, or
if you want to use TimeFrameSet then you need to use SetForeign in proper order as described in the Knowledge Base:

Generally EVERYTHING is either described in the Users' Guide or in the Knowledge Base.

1 Like