Passing an optional or default parameter to a user-defined function

I wanted to know how I can go about passing an optional/default parameter to a user-defined function. If I try to do it the C++ way it gives me a syntax error (sample code below). This is possible in some of the in-built functions like Plot(). Similarly, is it possible to have default parameters in user-defined functions?

function UserDefinedFunctionWithOptionalParameters(optionalParam = 0) {
	printf("optionalParam = %g", optionalParam);
}
// Gives a syntax error.

UserDefinedFunctionWithOptionalParameters() // Should print 'optionalParam = 0'

It is not possible that way in AFL.

But to enable default value you may do like this (setting argument to Null on function call).

function UserDefinedFunctionWithOptionalParameters(optionalParam) {
	printf("optionalParam = %g", Nz(optionalParam, _default = 0));
}

// Should print 'optionalParam = 0' if argument being Null
UserDefinedFunctionWithOptionalParameters(Null);

You may do similar via AmiBroker ADK (AmiBroker development kit).
See AmiBroker download page.

2 Likes

Default parameters are only supported by internal AmiBroker functions and by plugin-exported functions.

1 Like