[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Calling your own functions



PureBytes Links

Trading Reference Links

Yes it is possible but you need to include definition of the function using #include
command. Simple solution is to create MyFunctions.afl file where you will put ALL your functions, save it into "Include" folder
and then you will be able to reference it using
 
#include <MyFunctions.afl>
 

Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message -----
Sent: Wednesday, January 30, 2008 4:23 AM
Subject: [amibroker] Calling your own functions

I am evaluating AmiBroker at the moment, but can't figure out whether the following is possible. I want to create a new function that can be called from within a formula and used for backtesting. Just as if you were to call, say, the inbuilt MACD or Chaikin functions.

Just to test if it were possible, I grabbed a function from the manual and saved it as a new formula:

function IIR2( input, f0, f1, f2 )
{
result[ 0 ] = input[ 0 ];
result[ 1 ] = input[ 1 ];
for( i = 2; i < BarCount; i++ )
{
result[ i ] = f0 * input[ i ] +
f1 * result[ i - 1 ] +
f2 * result[ i - 2 ];
}
return result;
}


Then I created a new formula to call this function from, again just copying straight from the manual:

Plot( Close, "Price", colorBlack, styleCandle );
Plot( IIR2( Close, 0.2, 1.4, -0.6 ), "function example", colorRed );


Amibroker complains about the second line:
Ln: 2, Col: 11: Error 31. Syntax error, expecting ')' or ','

Any idea what's going on? Do I have to compile the function or something like that? (If so, how do I?).

My second question is whether we can get access to the source of the inbuilt functions so that I can learn how to create my own that can be called from backtesting.  I'd like to be able to do the following:
Buy=Cross(myfunction(xyz), 5);
But I'm not sure how to write the function so it can be used like this.  If we can't get the source, then does anyone have any hints on how to convert a custom indicator to a function?

Many thanks in advance!

__._,_.___

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___