How to use Timeframeexpand for volume/range bars

just checking the reference, it is not explained how to use timeframeexpand on non-time bars like range or volume bars. Please have a look at following chart. The original chart is running at 75000V bars.

bigmad = ema(C,21)-ema(C,55);
bigmaup = bigmad >Ref(bigmad ,-1);
bigmadown=bigmad <Ref(bigmad ,-1);

Buy= cond1 and ref(bigmaup,-1) and bigmaup ; 

ref(bigmaup ,-1) is not alligned on lower tf i.e. 75000V bars.

please help how to do it?

It is explained in the manual.
It is said loud and clear in ORANGE boxes to catch attention of those who scan, not read.

Citation from

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").

So read the manual again and ALWAYS, I mean ALWAYS use TimeFrameExpand.

The usage is pretty much the same regardless of compression mode.

taking 3rd example in the documentation page at

/* switch to weekly time frame */
TimeFrameSet( inWeekly );
whist = MACD( 12, 26 ) - Signal( 12, 26, 9 );
wtrend = ROC( whist, 1 ); // weekly trend - one week change of weekly macd histogram

/* expand calculated MACD to daily so we can use it with daily signals */
wtrend = TimeFrameExpand( wtrend, inWeekly );

if we do operations on volume bars as follows lets say

TimeFrameSet( 150000);
whist = MACD( 12, 26 ) - Signal( 12, 26, 9 );
wtrend = ROC( whist, 1 ); 

/* expand calculated MACD to daily so we can use it with daily signals */
wtrend = TimeFrameExpand( wtrend, "WHAT SHOULD BE WRITTEN HERE" );

if we need to make timeframe* operations on volume/range bars how to do it?

Volume based bars use special encoding as described in the user's manual.

It is also possible to use n-volume bars in TimeFrame functions without calling TimeFrameMode() - it is then necessary to specify n-volume bars as negative number offset by -1000000 (minus one million):
TimeFrameSet( -1000000 - 2000 );

So if you have 150000 in TimeFrameSet you can use TimeFrameExpand with value of (-1000000 - 150000 ) = -1150000

1 Like

Thanks for resolving the issue. Is there any similar way to encode range bars also? Further, Is there any way to check what TF chart is running from afl?

I really appreciate your patience in resolving these novice questions.

Sure and it is also described in the docs. Read the docs.

timeframeexpand is not allowing figures below 1 million

Would you READ precisely what was written? I wrote

you can use TimeFrameExpand with value of (-1000000 - 150000 ) = -1150000

You called TimeFrameSet, not TimeFrameEXPAND as was written. It is TimeFrameEXPAND that allows that, not TimeFrameSet that you erronously used.

sorry sent wrong screen shot earlier, using it on timeframeexpand only. I am extremely sorry for bothering you.

Post actual CODE (as text but using CODE TAGS), not screenshots showing one line of code. No one knows what you are doing if you just post screenshot showing half of the line. Learn basic rules of this forum. Please follow this advice: How to ask a good question

1 Like
bigrr = EMA(C,20);
bigrrup = bigrr>Ref(bigrr,-1);
hj = TimeFrameExpand(bigrr,-1150000);

Exact usage depends on AmiBroker version you are using.
Despite the fact that rules of this forum clearly REQUIRE you to provide crucial information, including AmiBroker version that you are using, you did not provide that.

As error message says "... not allowed anymore. Use TimeFrameMode to set volume bar" which means exactly what it says:

"not allowed anymore" - means that the version you are using (GOD KNOWS what, because I don't), does not allow that any more.

"Use TimeFrameMode to set volume bar instead" - means what it says - use TimeFrameMode function.

So instead of old style

hj = TimeFrameExpand(bigrr,-1150000);

You should do what Amibroker tells you. Which is to use TimeFrameMode before TimeFrameExpand for range/volume modes.

Version(6.20); //  requires relatively new version
// as error message said use
TimeFrameMode(2); // we switch the mode 
hj = TimeFrameExpand(bigrr,150000); // this uses VOLUME bars and we don't need minus anymore

Really error messages in AmiBroker are super informative, if only users would actually read them and followed advice.

Thanks for your reply and your patience.

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