PureBytes Links
Trading Reference Links
|
Hi David --
See if this helps.
It has not been tested completely, and may have coding errors in it.
Thanks, Howard
// Multiple Systems in One AFL.afl
// An outline of a technique for combining multiple trading systems
// in a single afl // // Howard Bandy // www.quantitativetradingsystems.com // // This was done quickly and tested lightly. // It is intended to be educational -- not necessarily profitable.
// Verify that it works for you before using it. // // Assumptions: // 1. Only long trades are taken. // All systems can be only Long or Flat. // 2. System A is a trend following system
// and is the "boss". // Whenever A is Long, B cannot make a trade. // 3. System B is a swing trading system // It goes Long or Flat, but only when A is Flat.
// Code for System A
// Assume it is long term moving average crossover // or breakout. FastMA = MA(C,10); SlowMA = MA(C,100); BuyA = Cross(FastMA,SlowMA); SellA = Cross(SlowMA,FastMA); // Code for SystemB
// Assume it is mean reversion system. // Buy every time the fast stochastic rises through 10 // Sell every time the fast stochastic drops through 90 // FastStoch = StochK(5,3); BuyB = Cross(FastStoch,10);
SellB = Cross(90,FastStoch);
// Combine the two systems
// Set up a "state" corresponding to whether System A is Long or Flat AIsLong = Flip(BuyA,SellA); AIsFlat = Flip(SellA,BuyA);
// Buy whenever there is a Buy Signal from System A, // or a Buy Signal from System B while System A is Flat. Buy = BuyA OR (AIsFlat AND BuyB);
// Two different exit conditions -- pick one.
// Sell on either sell signal. //Sell = SellA OR SellB;
// Or -- Exit System A only from Systems A's Sell Sell = SellA OR (AIsFlat AND SellB);
Plot(C,"C",colorBlack,styleCandle);
Plot(FastMA,"FastMA",colorGreen,styleLine); Plot(SlowMA,"SlowMA",colorBlue,styleLine); PlotShapes(shapeSmallCircle*BuyB+shapeSmallCircle*SellB, IIf(BuyB,colorGreen,colorRed)); PlotShapes(shapeUpArrow*Buy+shapeDownArrow*Sell,
IIf(Buy,colorGreen,colorRed));
Plot(FastStoch,"FastStoch",colorRed,styleLine|styleLeftAxisScale); Plot(90,"90",colorYellow,styleLine|styleLeftAxisScale); Plot(10,"10",colorYellow,styleLine|styleLeftAxisScale);
Plot(AIsFlat,"AIsFlat",colorGreen,styleLine|styleLeftAxisScale);
On 5/5/07, Fred <
ftonetti@xxxxxxxxxxxxx> wrote:
For starters try explaining it so that someone outside of yourself
understands what it is are trying to accomplish without having to ask
additional questions ...
--- In amibroker@xxxxxxxxxxxxxxx, "optiekoersen" <optiekoersen@xxx>
wrote:
>
> Okay, thanks for this advice. Seems an impressive and useful book.
> But for the moment I am at a death point. Are there anymore
> suggestions how I can solve this issue quickly?
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "David Fitch" <davidfitch@>
> wrote:
> >
> > You might try Howard Bandy's Book, Quantitative Trading Systems.
He
> covers this as well as many other subjects. And it includes AFL
> examples as well.
> > Dave
> >
> > ----- Original Message -----
> > From: optiekoersen
> > To: amibroker@xxxxxxxxxxxxxxx
> > Sent: Saturday, May 05, 2007 6:30 AM
> > Subject: [amibroker] mixing two systems
> >
> >
> > I have two systems. A trendfollowing one and a trendreversal
> system.
> > I use them seperately. Normally I use the trendfollowing system
> untill
> > I get a signal from my trendreversal one. Now I would like to
put
> them
> > together in 1 code. The problem is that after getting a buy
from
> my
> > trendreversal system I do not like to follow signals from my
> > trendfollowing system until my stoploss or profit is reached.
> >
> > I seriously have no idea which arguments I should use to solve
> this
> > problem. Is there anyone who can help me further?
> >
>
__._,_.___
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
SPONSORED LINKS
__,_._,___
|