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

RE: [amibroker] Problem with using "function" in AFL



PureBytes Links

Trading Reference Links

I'm can't explain why it works one way and not the other.

This code give a compile error at this line:

Buy = Buy_Cond1;

The reason is Buy_Cond1 is undefined because it is inside a function and
is local to that function.

Add this line as the last line of your function:
    return Buy_Cond1:

Then change your function call to:

    Buy = rule1(10,1.5,1.005);
--
Terry
-----Original Message-----
From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On
Behalf Of soundscribe_studios
Sent: Saturday, May 27, 2006 15:24
To: amibroker@xxxxxxxxxxxxxxx
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

 
Yahoo! Groups Links



 




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get to your groups with one click. Know instantly when new email arrives
http://us.click.yahoo.com/.7bhrC/MGxNAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

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

 
Yahoo! Groups Links

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

<*> 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/