Skip to main content

Buy at an Extreme Low Point for Amibroker (AFL)

JackTheMan18 over 13 years ago Amibroker (AFL)

  • Rating:
    2 / 5 (Votes 5)
  • Tags:
    trading system, amibroker

Based on an idea by Nat Stewart in Active Trader Magazine, December 2012:
The Low Close Edge
Stewart presented several different versions of the low-close strategy in the article, but I generalized it for this snippet of a trading program.
The concept is simple: buy the stock when it closes in the bottom NperIn% of its daily range,
AND in the bottom NperIn% of its LookBackIn day range.
When it closes in the top NperOut% of its daily range
AND in the top NperOut% of its LookBackOut day range, liquidate the position and return to cash.

Indicator / Formula

Copy & Paste Friendly
NperIn = Optimize("NPerIn", 10, 10, 40, 5); /* The close has to be less than this % of its daily and N day range */
LookBackIn = Optimize("LookBackIn", 17, 5, 21, 1); /*LookBack Period of Days for Close % determination */

LExitDays = Optimize("LExitDays", 5, 1, 30, 1);
SExitDays = Optimize("SExitDays", 5, 1, 30, 1);

/* */

NperOut = 2* NperIn;/* The close has to be less than this % of its daily and N day range */
LookBackOut = LookBackIn/2; /*LookBack Period of Days for Close % determination */
IndexLen =200;
/*****************************************************************************************************************/   
//Indicator #1 - On the Current Bar, what % is the Close
Condition1 =  (100 * (C-L) / (H-L)) < NperIn;
Condition10 = (100* (C-L) / (H-L)) > 100-NperOut;
//Indicator #2 - In the past Len1 days,  
Condition2 =  100 * (C - LLV(L,LookBackIn)) / (HHV(H,LookBackIn) - LLV(L,LookBackIn)) < NperIn;
Condition20=  100 * (C - LLV(L,LookBackOut)) / (HHV(H,LookBackout) - LLV(L,LookBackout)) >100- NperOut;

//Indicator #4 - Long Term Market
StrongTrendUp =   Close > MA(Close, IndexLen) AND MA(Close,IndexLen) > Ref(MA(Close,IndexLen),-1) ;
StrongTrendDn =   Close < MA(Close, IndexLen/4)   AND MA(Close,IndexLen/4) < Ref(MA(Close,IndexLen/4),-1) ;
TrendLess = NOT(StrongTrendDn OR StrongTrendUp);
/*****************************************************************************************************************/  
Buy =  Condition1 AND Condition2  AND NOT StrongTrendDn; 

Short = False;    
Sell= Ref(Buy, -LExitDays) OR Short OR (Condition10 AND Condition20) ;    
Buy= ExRem(Buy, Sell);     
Sell= ExRem(Sell, Buy) ;
    
Cover=Ref(Short, -SExitDays) OR Buy OR (Condition1 AND Condition2);     
Short= ExRem(Short, Cover);     
Cover= ExRem(Cover, Short);     
    

9 comments

1. hotaro3
over 13 years ago

gives error at lines 24 and 28 due to no definition for LExitDays and SExitDays

6. RBuck
over 13 years ago

Interesting approach . . . when I added my standard optimization, walk-forward and stop loss routines the approach, it provided a better than 30% annualized return for a 2 month train, 2 month step walk-forward 2011 – 2012 against a 3 position portfolio of the current IBD Top Fifty.

Unusual was the overall return . . . of the 464/848 trades all were long, average days held were 2.22, maximum trade % draw-down -17%, maximum system % draw-down -18%.

I consider better than 30% annual return on out-of-sample test, outstanding. Good work. by grace, RBuck

over 13 years ago

it shows blank white screen, seems something is wrong with the code. please fix.

Leave Comment

Please login here to leave a comment.