How to define a constant (but variable)?

Hello AmiBroker Support Team :blush:

How to define a constant (but variable)?
I mean such a situation:
I define as a constant the symbol "xz",
in the following way:
if the current share price is 110.20, then xz = 110.00
if the current share price is 110.50, xz = 111.00
if the current share price is 110.60, then xz = 111.00
(similarly, at the price: 0.87 to, xz = 0.90 and if 39.45 it, 39.50 according to stock exchange requirements)
So how do you define a constant that changes, rounds to the nearest, full current price?

greetings :blush:

Is it really so difficult using forum search?

function RoundToDecPlaces( value, decplaces ) {
    /// at Amibroker forum:
    /// @link https://forum.amibroker.com/t/how-to-define-a-constant-but-variable/9374
    /// @link https://forum.amibroker.com/t/roundup-function-in-amibroker/6350/3
    powten = 10^decplaces;
    result = round(value * powten) / powten;
    return result;
}

value = MxFromString( "[110.2;110.5;110.6]" );

for( i = 0; i < MxGetSize(value,0); i++ )
{
	printf( "Raw value: %1.2f\n", value[i][0] );
	printf( "rounded: %1.2f\n\n", RoundToDecPlaces( value[i][0], 0 ) );
}

value = 0.87;
printf( "Raw value: %g\n", value );
printf( "rounded: %1.2f\n\n", RoundToDecPlaces( value, 1 ) );

value = 39.45;
printf( "Raw value: %g\n", value );
printf( "rounded: %1.2f\n\n", RoundToDecPlaces( value, 1 ) );
5 Likes