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

Re: [amibroker] Need AFL assistance; how to handle variables?



PureBytes Links

Trading Reference Links

Dear Dag,

Yes indeed, AFL is somewhat different than "normal" or general-purpose
programming languages. It is simply tweaked towards writing trading rules.

First (already discussed) thing is that IIF() is a function not a statement.
It returns an array of results.

The formula for your strategy is far simpler than you thought. In fact you
don't need IIF() at all !

priceup = close > ref( close, -1 );
pricedown = close < ref( close, -1 );

buy = sum( priceup, 3 ) > 1;
sell = sum( pricedown, 3 ) > 1;

The only thing I can suggest is changing >1 with >2 to get smaller number of signals.

Best regards,
Tomasz Janeczko
===============
AmiBroker - the comprehensive share manager.
http://www.amibroker.com


----- Original Message ----- 
From: <d-erland@xxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Saturday, March 10, 2001 2:08 PM
Subject: [amibroker] Need AFL assistance; how to handle variables?


> Hi,
> 
> I want to implement a simple strategy in AFL. I want to generate buy 
> signals when the close of 2 of the 3 last days have gone up (compared 
> to previous day's close), sell when 2 of the last 3 have gone down. 
> 
> To do this I create a variable and try to increase it if "ref(close, -
> 1) > close" but it just doesn't work. Beeing a software developer I 
> kind'o apply the same programming techniques in AFL that in other 
> programming languages, but I've started to see that AFL works quite 
> differently. For clarity, could someone please review the AFL code 
> bellow and give suggestions on how to solve it in an AFL'ish way? ;)
> 
> /*----------------- code start -----------------------------*/
> BC = 0;
> SC = 0;
> 
> // Count days rising
> iif(ref(close, -1) < close, BC=BC+1, BC=BC);
> iif(ref(close, -2) < ref(close, -1), BC=BC+1, BC=BC);
> iif(ref(close, -3) < ref(close, -2), BC=BC+1, BC=BC);
> 
> // Count days falling
> iif(ref(close, -1) > close, SC=SC+1, SC=SC);
> iif(ref(close, -2) > ref(close, -1), SC=SC+1, SC=SC);
> iif(ref(close, -3) > ref(close, -2), SC=SC+1, SC=SC);
> 
> // buy if 2 or 3 days have gone up
> buy = BC > 1;
> 
> // buy if 2 or 3 days have gone down
> sell = SC > 1;
> 
> // debuging
> writeval(BC);
> writeval(SC);
> graph0 = BC;
> graph1 = SC;
> 
> /*----------------- code end -----------------------------*/
> 
> BC and SC is always 3 !
> 
> Regards,
> Dag Erlandsen
> 
> 
> 
> 
> 
> 
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 
> 
>