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

[amibroker] Re: Calling your own functions



PureBytes Links

Trading Reference Links

Your function and two plot lines work fine for me as you've shown
them. No errors are reported.

>> Buy=Cross(myfunction(xyz), 5);

Provided "myfunction" returns an array, that should be fine. The basic
idea is you first look at what sort of variable is required where you
want to put the function (in this case the first argument to "Cross"),
and then make sure your function returns that sort of argument. Source
code is not required.

The main thing to remember is that built-in functions are not written
in AFL, but compiled to machine code, so will run significantly faster
than the equivalent AFL. You can do that as well using the plugin
development kit (ADK) available on the AB website, but obviously it's
a lot more involved and you need other tools (compiler) and
programming skills.

Regards,
GP


--- In amibroker@xxxxxxxxxxxxxxx, "justjuice200" <justjuice200@xxx> wrote:
>
> 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
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/