AFL language allows us to define reusable functions that can be used in our formulas. The following chapter of the manual explains the procedure in details: http:\/\/amibroker.com\/guide\/a_userfunctions.html<\/a><\/p>
To create such file we should do the following:<\/p>
Create a new formula. The preferred location is in Include folder in chart windows, we can in fact choose any custom location of the file.
<\/p>
We can also rename the file to a descriptive name, for example myfunctions.afl:
<\/p>
Now we can edit the file and paste our function definitions, then save the file:
<\/span>function <\/span>myMACD<\/span>( array, <\/span>fast<\/span>, <\/span>slow <\/span>)
{
return <\/span>EMA<\/span>( array, <\/span>fast <\/span>) - <\/span>EMA<\/span>( array, <\/span>slow <\/span>);
<\/code>
Now in our main file we can use only a reference to myfunctions.afl file:<\/span>\/\/ include our definitions
#include <myfunctions.afl>
\/\/ use of function
<\/span>Plot<\/span>( <\/span>myMACD<\/span>( <\/span>High<\/span>, <\/span>12<\/span>, <\/span>26 <\/span>), <\/span>"Open MACD"<\/span>, <\/span>colorRed <\/span><\/code><\/ol>We don’t have to specify the path, because we saved our formula in the folder, which is specified as a ‘default include path’ in Tools\u2013>Preferences\u2013>AFL<\/strong>:<\/p>
<\/p>
In other cases we should provide full path to the file – #include is a pre-processor command, therefore this time we use single backslashes in the path:<\/p>
#include “C:\\Program Files\\AmiBroker\\AFL\\common.afl”<\/p>
More information about include command can be found at:<\/p>
http:\/\/www.amibroker.com\/guide\/afl\/_include.html<\/a><\/p>","protected":false},"excerpt":{"rendered":"