User-Defined Function calls vs. #include

After 20+ years of owning AB, I'm finally (very slowly) starting down the path of actually learning AFL instead of trying to get by being a cut-and-paste code robber, so this is just one of possibly many real stupid questions that I might be asking.

I can't locate any guidelines regarding when it's more appropriate to call code from a file using #include and when to call a user-defined function / code snippet.

BTW, I'm using the very helpful guidelines in the "How to Learn AFL" thread supplemented with YouTube C-language tutorials and I've actually made some rather profound progress in my understanding of user-defined functions and loops. So, thanks to all that made contributions to that thread.

1 Like

These two are not one vs another. They can be used at the same time.

#include is a way to tell AMiBroker to include (like "copy paste") the content of the file in the place where #include command is. Instead of physically copy-pasting the content of the file, you can use #include and it will work the same as the code was placed in there.

User-defined function is different idea. It is just a piece of code that you define once and you can call many times later with different parameters. Used-defined function is just a function (the fact that it is "user defined" does not change anything). For example you can define cube function

function cube( x )
   return x*x*x;

And later in the code just use

y1 = cube( 5 );
y2 = cube( 3 );

You can call it many times with different parameters and it will compute some results depending on parameters.

User-defined function can be placed in the main file OR in the included file.

So you can use BOTH #includes and user-defined functions in the very same program.


This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.