Saturday, November 6, 2010

Developing an Auto Trading System

UPDATE - this is the link to the article

http://www.adaptrade.com/BreakoutFutures/Newsletters/Newsletter0305.htm


If you've embarked on developing a trading system with auto execution, you have no doubt discovered that it's not that easy to find something that offers consistent profits.  You have all kinds of idea but not sure how to test them all, thinking it could take forever plus a day to find the right one.  Well there is something called Rapid Prototyping that can help you out.  There's a great article written about this and some AFL to go along with it.  Here's the info and links to get you started.

Article with a great explanation

Original AFL - You may have to fix line breaks to make this code work

// Rapid Prototyping Method for Trading System Development

// Idea from "The Breakout Bulletin March 2005" by Mike Bryant
// AFL coding by mmike

SetTradeDelays(1,1,1,1);
Cond1 = C-Ref(C,-1);
Cond2 = C-Ref(C,-2);
Cond3 = C-Ref(C,-5);
Cond4 = C-Ref(C,-10);
Cond5 = C-MA(C,5);
Cond6 = C-MA(C,25);
Cond7 = C-MA(C,45);

w1 = Optimize("w1",1,-1,1,1);
w2 = Optimize("w2",-1,-1,1,1);
w3 = Optimize("w3",-1,-1,1,1);
w4 = Optimize("w4",1,-1,1,1);
w5 = Optimize("w5",0,-1,1,1);
w6 = Optimize("w6",0,-1,1,1);
w7 = Optimize("w7",0,-1,1,1);

Buy = w1*Cond1>=0 AND w2*Cond2>=0 AND w3*Cond3>=0 AND w4*Cond4>=0 AND
w5*Cond5>=0 AND w6*Cond6>=0 AND w7*Cond7>=0;
Sell = w1*Cond1<=0 AND w2*Cond2<=0 AND w3*Cond3<=0 AND w4*Cond4<=0 AND
w5*Cond5<=0 AND w6*Cond6<=0 AND w7*Cond7<=0;
Short = Sell;
Cover = Buy;


AFL Code modified by me trying out a TTM system

// Rapid Prototyping Method for Trading System Development

// Idea from "The Breakout Bulletin March 2005" by Mike Bryant
// AFL coding by mmike

SetTradeDelays(1,1,1,1);
Plot( C, "Close", colorBlue, styleNoTitle
styleBar
styleThick );


/* Original test system
Cond1 = C-Ref(C,-1);
Cond2 = C-Ref(C,-2);
Cond3 = C-Ref(C,-5);
Cond4 = C-Ref(C,-10);
Cond5 = C-MA(C,5);
Cond6 = C-MA(C,25);
Cond7 = C-MA(C,45);
*/

// TTM and MA

HaClose = (O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
barcolor = IIf(HaClose >= HaOpen, colorBlue, colorRed);

//Plot( C, "Close", BarColor , styleNoTitle
styleBar
styleThick);

TTM = IIf(HaClose >= HaOpen, 1, 0);

Cond1 = TTM;
Cond2 = Ref(TTM,-2);
Cond3 = Ref(TTM,-3);
Cond4 = Ref(TTM,-4);
Cond5 = C>MA(C,5);
Cond6 = C>MA(C,50);
Cond7 = C>MA(C,200);


w1 = Optimize("w1",1,-1,1,1);
w2 = Optimize("w2",-1,-1,1,1);
w3 = Optimize("w3",-1,-1,1,1);
w4 = Optimize("w4",1,-1,1,1);
w5 = Optimize("w5",0,-1,1,1);
w6 = Optimize("w6",0,-1,1,1);
w7 = Optimize("w7",0,-1,1,1);

w1 = -1;
w2 = -1;
w3 = 0;
w4 = -1;
w5 = 1;
w6 = -1;
w7 = -1;

Buy = w1*Cond1>=0 AND w2*Cond2>=0 AND w3*Cond3>=0 AND w4*Cond4>=0 AND
w5*Cond5>=0 AND w6*Cond6>=0 AND w7*Cond7>=0;
Sell = w1*Cond1<=0 AND w2*Cond2<=0 AND w3*Cond3<=0 AND w4*Cond4<=0 AND
w5*Cond5<=0 AND w6*Cond6<=0 AND w7*Cond7<=0;
Short = Sell;
Cover = Buy;

3 comments:

  1. Hi
    After reading your mail I thought you have dropped auto trading forever.This article shows that you are still exploring new things.Good.keep sharing.

    ReplyDelete
  2. nice post. thanks.

    ReplyDelete
  3. I like your article and it really gives an outstanding idea that is very helpful for all the people on web.

    ReplyDelete

Let's hear what you have to say!

Disclaimer

The information presented on this site is for educational and entertainment purposes only. This site contains no suggestions or instructions that you must follow, do your own research and due diligence before committing your cash to the markets. Your on your own.