PureBytes Links
Trading Reference Links
|
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
|