Why TimeFrameExpand is essential (Warning 509)

As it is very clearly written in Tutorial on Using TimeFrame functions

IMPORTANT: TimeFrameExpand IS REQUIRED for any formula that uses TimeFrame* functions. If you don't expand time compressed data you will have incorrect timestamps (see description below in "How it works").

This post is to show why calling TimeFrameExpand() is essential when you called TimeFrameSet/TimeFrameCompress.

The point I am trying to make is that TimeFrameSet causes that all time-compressed values are squeezed at the end of the array and when they are squeezed, they do NOT correspond to "normal" timestamps. Only after they are expanded, they are placed in correctly timestamped array cells.

Lets look at this code:

Filter = 1;
AddColumn(Close, "Close");
TimeFrameSet( 5 * in1Minute );
x = Close;
AddColumn( x, "5-minute compressed (timestamps incorrect)");
AddColumn( TimeFrameExpand( x, 5 * in1Minute), "5-minute expanded (timestamps correct)");

Now look at the output.
I marked with colors what happens when you call TimeFrameSet. The array elements that represent 5-minute closing prices get squeezed at the end of the array (so they do not match the timestamps). Only after you call TimeFrameExpand - timestamps match again (see colored lines)


So, any use of array that was created via TimeFrameSet or TimeFrameCompress is correct ONLY if you call TimeFrameExpand.

So instead of wanting to "suppress" warning 509, just do the correct thing and just call that TimeFrameExpand() function. It is that easy.