[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: mixing two systems



PureBytes Links

Trading Reference Links

Hi,

Is changed the code for my own two systems.
System1: Long, Sell, Profit, Stoploss.
System2: Long, Short, Sell, Cover, Profit, Stoploss.

But somehow the profit and lossstops do not function properly for 
system1. Somewhere in the code must be a small misstake, which I 
could not find. Anybody an idea?

BuySystem1   = Condition1 AND insession;
SellSystem1  = TimeNum() >= BTEndTime ;

LongStop = ValueWhen(Buysystem1,Low)-pds1;
TakeProfitAmount = pds2*(BuyPrice-LongStop);
LongStopAmount = BuyPrice - LongStop;
StopSystem1    = ApplyStop(stopTypeLoss,stopModePoint,LongStopAmount, 
ExitAtStop = 1, volatile = False, ReEntryDelay = 0 );
ProfitSystem1 =ApplyStop
(stopTypeProfit,stopModePoint,TakeProfitAmount, ExitAtStop = 1, 
volatile = False, ReEntryDelay = 0 );


BuySystem2   = Sum(buysig,2) > Sum(Sellsig,2) AND insession AND NOT 
GapUp() OR GapDown() AND NOT Holiday; 
ShortSystem2 = Sum(buysig,2) < Sum(Sellsig,2) AND insession AND NOT 
GapDown() OR GapUp() AND NOT Holiday;

SellSystem2  = PDI(23) < pds14  AND Sum(buysig,2) > Sum(Sellsig,2) OR 
MDI(23) > 35 AND Sum(buysig,2) > Sum(Sellsig,2) OR TimeNum() >= 
BTEndTime; 
CoverSystem2 = MDI(23) < pds15  AND Sum(buysig,2) < Sum(Sellsig,2) OR 
PDI(23) > 35 AND Sum(buysig,2) < Sum(Sellsig,2) OR TimeNum() >= 
BTEndTime;

System1IsLong = Flip(BuySystem1,SellSystem1);
System1IsFlat = Flip(SellSystem1,BuySystem1);

Buy   = BuySystem1 OR (System1IsFlat AND BuySystem2) ;
Sell  = SellSystem1 OR (System1IsFlat AND SellSystem2) ;
Short = System1IsFlat AND ShortSystem2 ;
Cover = System1IsFlat AND CoverSystem2 ;

StopSystem2   = ApplyStop(stopTypeLoss,stopModePoint,Optimize("max. 
loss stop level",3.0,3.0,3.0,1.0),True,True,1 );
ProfitSystem2 = ApplyStop(stopTypeProfit,stopModePoint,Optimize("max. 
profit stop level",55,55,55,5),True,True,1 );
SetTradeDelays(1,1,1,1);

Profit = System1IsLong AND Profitsystem1 OR (System1IsFlat AND 
ProfitSystem2) ;
Loss   = StopSystem2 OR (System1IsFlat AND StopSystem2) ;

PositionSize = 100 * 1;


--- In amibroker@xxxxxxxxxxxxxxx, "optiekoersen" <optiekoersen@xxx> 
wrote:
>
> Hi Howard,
> 
> Thanks a lot for the help. It looks a lot of how I have it in mind.
> I will rebuild the code for my two systems. With your suggestions 
it 
> probably will be a success.
> 
> Greets,
> Ronald
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "Howard B" <howardbandy@> wrote:
> >
> > 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@> 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 <amibroker%40yahoogroups.com>,
> > > "optiekoersen" <optiekoersen@>
> > >
> > > 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 <amibroker%
> 40yahoogroups.com>, "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 <amibroker%40yahoogroups.com>
> > > > > 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
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/