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 [email protected], "justjuice200" <[EMAIL PROTECTED]> 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! >
