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

help with AFL - repost



PureBytes Links

Trading Reference Links

I'm reposting this since I still haven't figured it out.

Here's what I'm trying to code.

Entry:
- based on certain buy conditions (called Buyconditions in my AFL)
- hold buy conditions to be true for "x" days (after which, a buy 
should not occur, even if the buy conditions are still true)
- buy price should be "y" more than the high of the day the buy 
signal occurred (i.e. High + y)

Exit:
- sell at the close if "z" days have passed OR sell if the price goes 
below the low of the day before buy signal occurred, i.e. Ref(L, -1)

Here's my AFL so far but it doesn't seem to do what I'm trying to 
do. Any help would be GREATLY appreciated.

Buy = 
Buyconditions
;

Buy = Hold (Buy, x);

BuyPrice = ValueWhen(Buy, High) + y;

Sellcond1 = Ref(Buy,-z); // sell after z days
Sellcond2 = L <= ValueWhen(Buy, Ref(L,-1)); // sell if price goes 
below the low of the day before the buy signal occurred

Sell =
Sellcond1 OR Sellcond2
;

SellPrice= IIf(Sellcond1, C, ValueWhen(Buy, Ref(L,-1))); // If z 
days have passed, sell at the close. If price has dropped below the 
low, sell at that low.

/////////////////