Timeframeexpand seems to skip ahead an interval?

Greetings,
I am attempting to find a more efficient way to sum the up ticks every 30 minutes using tick base interval, assign the value to a static variable, then call and plot this static variable in a 30 minute interval chart. I got this to work with an IIF statement but would like to use the timeframe funcitons to increase efficiency.

UP_TICK = IIf( C > Ref( C , -1 ) , v , 0 ) ;

TPO_UP_TICK_SUM_30_MIN_COMPRESS = TimeFrameCompress( UP_TICK , 2 * in15Minute , compressVolume ) ;

TPO_START = IIf( ( Minute() == 00 AND Ref( Minute() , -1 ) > 00 ) OR( Minute() == 30 AND Ref( Minute() , -1 ) < 30 ) , 1 , 0 ) ;

TPO_UP_TICK_SUM = IIf( TPO_START != 1 , Sum( UP_TICK , BarsSince( TPO_START ==  1 ) + 1 ) , Sum( UP_TICK , 1 ) )  ;

x = TimeFrameExpand( TPO_UP_TICK_SUM_30_MIN_COMPRESS , 2 * in15Minute , expanDPOINT ) ;

STaticVarSet( "TPO_UP_TICK_SUM_30_MIN_COMPRESS_STATIC" , x ) ;

Filter = DateNum() == 1190111 AND Ref( TPO_START , 1 ) == 1 ;

AddColumn( StaticVarGet( "TPO_UP_TICK_SUM_30_MIN_COMPRESS_STATIC" ) , "TPO_UP_TICK_SUM_30_MIN_COMPRESS_STATIC" , 1.2 , colorDefault ,
           IIf( StaticVarGet( "TPO_UP_TICK_SUM_30_MIN_COMPRESS_STATIC" ) != TPO_UP_TICK_SUM , colorRed , colorGreen ) ) ;

AddColumn( TimeFrameExpand( TPO_UP_TICK_SUM_30_MIN_COMPRESS , 2 * in15Minute , expandPOINT )  , "TPO_UP_TICK_SUM_COMPRESS" , 1.2 , colorDefault ,
           IIf( TimeFrameExpand( TPO_UP_TICK_SUM_30_MIN_COMPRESS , 2 * in15Minute , expandPOINT ) != TPO_UP_TICK_SUM , colorRed , colorGreen ) ) ;

ADDCOLUMN( TPO_UP_TICK_SUM , "TPO_UP_TICK_SUM" , 1.2 ) ;

This is the analysis output

image

My question is why are some to the timeframecompress values equivalent to the iif statement values and others are not?

When I switch to expandfirst I get the following analysis output.


UP_TICK = IIf( C > Ref( C , -1 ) , v , 0 ) ;

TPO_UP_TICK_SUM_30_MIN_COMPRESS = TimeFrameCompress( UP_TICK , 2 * in15Minute , compressVolume ) ;

TPO_START = IIf( ( Minute() == 00 AND Ref( Minute() , -1 ) > 00 ) OR( Minute() == 30 AND Ref( Minute() , -1 ) < 30 ) , 1 , 0 ) ;

TPO_UP_TICK_SUM = IIf( TPO_START != 1 , Sum( UP_TICK , BarsSince( TPO_START ==  1 ) + 1 ) , Sum( UP_TICK , 1 ) )  ;

x = TimeFrameExpand( TPO_UP_TICK_SUM_30_MIN_COMPRESS , 2 * in15Minute , expanDFIRST ) ;

STaticVarSet( "TPO_UP_TICK_SUM_30_MIN_COMPRESS_STATIC" , x ) ;

Filter = DateNum() == 1190111 AND Ref( TPO_START , 1 ) == 1 ;

AddColumn ( UP_TICK , "UP_TICK" , 1.0 ) ;

AddColumn( StaticVarGet( "TPO_UP_TICK_SUM_30_MIN_COMPRESS_STATIC" ) , "TPO_UP_TICK_SUM_30_MIN_COMPRESS_STATIC" , 1.2 , colorDefault ,
           IIf( StaticVarGet( "TPO_UP_TICK_SUM_30_MIN_COMPRESS_STATIC" ) != TPO_UP_TICK_SUM , colorRed , colorGreen ) ) ;

AddColumn( TimeFrameExpand( TPO_UP_TICK_SUM_30_MIN_COMPRESS , 2 * in15Minute , expandFIRST )  , "TPO_UP_TICK_SUM_COMPRESS" , 1.2 , colorDefault ,
           IIf( TimeFrameExpand( TPO_UP_TICK_SUM_30_MIN_COMPRESS , 2 * in15Minute , expandFIRST ) != TPO_UP_TICK_SUM , colorRed , colorGreen ) ) ;

ADDCOLUMN( TPO_UP_TICK_SUM , "TPO_UP_TICK_SUM" , 1.2 ) ;

It seems like some of the timeframecompress values are jumping ahead an interval?

image

I feel like this issue is similar to the one in this post.


But I have not been able to figure out what I'm missing.

Thanks,
Mark

TimeFrame functions work as documented, see http://www.amibroker.com/guide/h_timeframe.html for the details. They don't do anything that is not documented, they don't jump, skip and don't do saltos.

Premature optimization is the root of all evil, so instead of "trying to increase efficiency" just stay with the code that already worked. Keep things simple. That is recipe for success.

The questions like "why my code works differently than your code" have one answer: because your code is different

Typically the only guidance that can be given is to spend more time debugging your own formula How do I debug my formula? or... if you already have code that works the way you wanted, stick with it instead of trying to "make it efficient".

1 Like