I have programming experience in Tradestation platform where we can use (easy language) for programming...i am not familier with the code which you sent.... but with this mail i am sending you the source code which is done by Tradestation program, it may help u to verify and convert according ur platform..
The code that I wrote is more or less similar to what you have provided except that I have included some 40 patterns along with 2 indicators in my afl.
May be, with strict stop loss conditions, my code may work or I need to read more theory about market conditions. Lets see.