PureBytes Links
Trading Reference Links
|
Folks,
I'm a new user - lurking on this group for a handful of months - just
now beginning to try to actually use AB.
I tried to code a simple moving average system which apparently is a
lousy system (huge negative return on backtesting with the limited
historical data I used (QQQ).
I'm hoping the more accomplished AB programmers/users on this group
can examine my afl code below and tell me if I'm missing "pieces" in
the system or recommend ways to improve the code (not necessarily the
system).
Again, I "tested" this on QQQ in the AA tool. Probably did messed
that up too.
I promise I'll begin reading the manual (beyond looking up syntax for
the Cross function, etc).
Thanks, much.
Michael
Anyway, here is the code:
/* MA Cross-Over System */
//maShort = 9;
maShort = Optimize("ShortMA Term",9,5,15,1);
//maLong = 36;
maLong = Optimize("LongMA Term",36,26,44,2);
// Buy at open if the previous day's short-term MA crosses above the
long-term MA
Buy = Ref(Cross(MA(Close,maShort),MA(Close,maLong)),-1) > 0;
// Exit with a profit or loss at the open if the previous day's short-
term MA crosses below the long-term MA
Sell = Ref(Cross(MA(Close,maShort),MA(Close,maLong)),-1) < 0;
// Exit with a loss if the stock goes against the position by more
than 4 times the 10-day ATR
ApplyStop(0,2,4*ATR(10),1);
|