PureBytes Links
Trading Reference Links
|
Hello there - what jumped out at me was
the return statement, communicating the
result of your user function to the rest of your AFL script. You fed it
the parameters and expected a result but it
wasn't communicated outside the brackets. Here's a
simple function. Feed it A and B
and it returns the results. Adds a value(STDEV) to the closing price.
Note these are arrays not point
values . I'm not sure what you're trying to do
with your function otherwise I would have
made notes on the
script. BTW there's are several
examples in the user guide. A user function requires, the
reserved word function, open brace close
brace, and a return. A
procedure is another matter as far and it doesn't return anything but does
something, and if you're interested in passing more than one value from your
user function you'll need to read up on global variables.
Hope this helps.
JOE
function Add( A,B)
{
Result = A + B;
return result;
}
Plot ( Close, "Close", colorBlack, styleLine);
B = StDev(Close,20);
Plot (ADD( C,B), "Result of
function", colorBlue, styleLine| styleThick);
----- Original Message -----
Sent: Saturday, May 27, 2006 4:23
PM
Subject: [amibroker] Problem with using
"function" in AFL
I need to call a function with parameters, but for
some reason I can't get it to work when using the variables passed into the
function. In the code below, if I explicitly set the variable values, the
function works fine -- executing about 80 trades. If I have them commented
out (and the passed in values are used), the system doesn't execute
any trades. I make no other changes.
I've plotted the values when
passed in and they appear to be correct. What am I missing here? This is AB
4.80.1 although it behaves the same on older versions as
well.
What's also odd is if I plot the "Buy" array, it looks exactly
the same whether or not the variables are explicitly set -- just no
trades get executed when the passed in values are used. At a loss
here...
///////////////////////////////// ... some code to read from
a file ...
function
rule1(aver,width,percent) {
//aver
=10; //width=1.5; //percent=1.005;
Bbot = BBandBot(Close,aver,width); Buy_cond1
= Close < BBot /percent; BuyPrice =
Close; }
if (p11 =
1) { //rule1(p12,p13,p14); rule1(10,1.5,1.005); }
....
some other code -- nothing touching Buy_cond1 or Buy ....
entrybar
= -1;
//Buy = Buy_cond1 AND Buy_cond2 AND Buy_cond3; Buy =
Buy_cond1;
// exit code
for( i = 0; i < BarCount; i++
) { if(
entrybar == -1 AND Buy[ i ] )
{
entrybar = i;
}
if(
entrybar != -1 AND i > entrybar AND Close[ i ] > Close[
entrybar ]+0.02 OR i-entrybar>=20 )
{
Sell[ i ] =
1; SellPrice[
i ] = Close[ i ];
entrybar =
-1;
} else
{
Sell[ i ] =
0;
} }
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 other support material please check also:
http://www.amibroker.com/support.html
SPONSORED LINKS
YAHOO! GROUPS LINKS
|
|