TimeFrameExpand expandPoint mode, was: expandLast-1 magic

Plotting 15min on 5min chart using Gfx....

Cond1    = ....;
Cond1     = TimeFrameExpand(Cond1, in15Minute);
    if(Cond1[i]) {
      GfxCircle(....);  }


add "expandLast-1" .... & it's work perfectly
So what magic expandLast-1 :exploding_head: did .....

Cond1     = TimeFrameExpand(Cond1, in15Minute,expandLast-1);


1 Like

Hi @Fossil,

Does expandFirst - 1 throws an error? Not in-front of my PC at this moment, unable to test it.



You should be using expand* constants without adding or subtracting anything. There are 3 possibilities: expandFirst, expandLast and expandPoint. These constants have numerical values that can be checked using for example this:

printf("%g %g %g", expandFirst, expandLast, expandPoint );

and they are 1, 0, 2. (expandLast - 1) would resolve to -1 which is NOT officially supported value, but since internal logic uses "fail-safe" behavior any value other than expandFirst and expandLast is treated as expandPoint, so your code should just use expandPoint.

And really it is all documented in the http://www.amibroker.com/guide/h_timeframe.html


TimeFrameGetPrice( pricefield, interval, shift = 0, mode = expandFirst )
What is default value/setting for mode if it is not set ?
Wil it be expandFirst ?

@tgbssk, when you examine the functions documentation, you can clearly distinguish the OPTIONAL parameters (i.e., the ones you can omit) and the DEFAULT values that are used in the function call when you do not specify them.
These are the ones that have an equal sign = followed by a value (the default).

In the case of:

TimeFrameGetPrice( pricefield, interval, shift = 0, mode = expandFirst )

both "shift" and mode are optional and they get the default values of 0 (for shift) and expandFirst (for mode).

So, for example, calling:

TimeFrameGetPrice( "O", inWeekly);

is equivalent to:

TimeFrameGetPrice( "O", inWeekly, 0, expandFirst); 

Please see also the last answer by @Tomasz in this recent discussion to further understand the matter.

1 Like

For further clarification: as @Tomasz wrote, the optional parameters in AFL are positional.

This means that you can't omit the shift param if you specify the mode one.

So if you by mistake write:

TimeFrameGetPrice( "O", inWeekly, mode = expandFirst); // WRONG

you are actually calling the function with these values:

// the constant value of 1 is wrongly assigned to the shift param!
TimeFrameGetPrice( "O", inWeekly, expandFirst, expandFirst); 

The values of the constants used in this function are: expandLast = 0, expandFirst = 1, expandPoint = 2


Thanx. I guessed for the same but just wanted to confirm it.

1 Like