Intraday value Timeframe

Please study the NullCount() function. It is very clearly explained in the KB link shared by fxshrat - Using loops with TimeFrame functions.

Initializing like this is unnecessary:

Since every count in AFL starts with Zero, if you happen to call the first element of an Array, 0 must be used in the subscript, as in, MSF[ 0 ] or LastC [ 0 ]. But to initialize an Array (in this case MSF), it is unnecessary to call using [].

Also refer to When scalar becomes an array, aka. type coercion in AFL

You can just write:
MSF = LastC; //MSF is an Array
or
MSF = 0; //Initialization as 0

With Loop:

TimeFrameSet( WhicheverHghrInterval );
	 //PLEASE READ THIS http://www.amibroker.com/kb/2014/11/25/using-loops-with-timeframe-functions/
	 //AND TRY OUT THE EXAMPLES SHOWN IN THE KB
	 start = NullCount( LastC ) + 1;
	 
	 CompMSF = LastC; //Compressed MSF array Init
	 for( i = start; i < BarCount; i++ ) {
		 prevMSF = CompMSF[ i - 1 ];
		 CompMSF[ i ] =  round( int( ( ( LastC [ i ] - prevMSF ) * 0.33 + prevMSF ) * 100 ) / 5 ) * 0.05;
	 }
TimeFrameRestore();

expandHow = expandFirst; //Otherwise expandLast or expandPoint (Depends on what you want to accomplish)
MSF = TimeFrameExpand( CompMSF, WhicheverHghrInterval, expandHow );

It is hard to tell what exactly you are trying to do. Without a Loop the same can also be written as:

MSF = 0;
MSF = ( ( ( ( LastC - Ref( MSF, -1 ) ) * 0.33 + Ref( MSF, -1 ) ) * 100 ) / 5 ) * 0.05;
MSFComp = TimeFrameCompress( MSF, WhicheverHghrInterval, compressLast );
expandHow = expandFirst; //Otherwise expandLast or expandPoint (Depends on what you want to accomplish)
MSFExp = TimeFrameExpand( MSFComp, WhicheverHghrInterval, expandHow );
//Then use MSFExp for plotting or for further calculation as per your requirements

The initial query with which you started this thread was very meticulously solved by fxshrat in his next post.

1 Like