Hi Evereyone. New to AFL and Amibroker. I am doing my best to use Google, older posts and everything else to try and get the basics of strategy testing down. So I was hoping someone might take a look at the code below and help me understand what I might be doing wrong. I would think a chandelier stop like the one below would result in at least some positive expectancy, but I keep getting negative returns. Maybe I am way off and maybe my strategy is terrible, but I am hoping that someone might point out a flaw in my coding as to why things are turning out so terribly.
Thanks!
//Strategy Name - 66 Bar breakout or Breakdown
//Limitations - 1 open positions per symbol at a time (No pyramiding)
SetPositionSize(1,spsPercentOfEquity);
SetOption("MaxOpenPositions",10);
//Long Strategy
Buy = C >= HHV(H,66)-1 AND C > MA(C,50) AND MA(C,50) > MA(C,200);
Sell = C == 0;
//Short Strategy
Short = C <= LLV(L,66)-1 AND C < MA(C,50) AND MA(C,50) < MA(C,200);;
Cover = C == 0;
//Stop Loss - Chandiler
ApplyStop(stopTypeTrailing, stopModePoint, 3*ATR(10), True, True );
From code point of view, the only thing that is "wrong" is C == 0 as you are comparing Close price to ZERO. Such thing will never happen for stocks (prices must be > 0 ). If you wanted condition that never happens you could just write Cover = False; or Cover = 0;
@neilkhess I think you should try to change your code to reference the previous bar values:
//Limitations - 1 open position per symbol at a time (No pyramiding)
SetPositionSize(1,spsPercentOfEquity);
SetOption("MaxOpenPositions",10);
//Long Strategy
Buy = C >= Ref(HHV(H,66), -1) AND C > MA(C,50) AND MA(C,50) > MA(C,200);
Sell = 0;
//Short Strategy
// Short = C <= Ref(LLV(L,66), -1) AND C < MA(C,50) AND MA(C,50) < MA(C,200);;
// Cover = C == 0;
//Stop Loss - Chandelier
ApplyStop(stopTypeTrailing, stopModePoint, 3*ATR(10), True, True );
Also, as you can see in the above-modified code, I suggest starting with a simpler formula (in my example, testing only the long side) to verify if it achieves what you want.