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

[amibroker] Re: Trading the equity curve



PureBytes Links

Trading Reference Links

Howard - thank you so much for this example. A great base to work off
of....

--- In amibroker@xxxxxxxxxxxxxxx, "Howard B" <howardbandy@xxx> wrote:
>
> Greetings all --
> 
> Here is an afl to trade the equity curve --
> 
> ///////////////////////////////////////////
> //    EquityCurveFeedback.afl
> //
> //    There are many ways to use the equity
> //    in the trading account, and its variation,
> //    to act as a filter to allow or block trades.
> //
> //    This code shows one example of applying
> //    trading system logic to the equity curve
> //    created by another trading system.
> //
> //    The first system is a simple moving
> //    average crossover -- it could be any system.
> //
> MALength1 = 14; //Optimize("MALength1",14,2,50,2);
> MALength2 = 13; //Optimize("MALength2",13,1,51,2);
> Buy = Cross(MA(C,MALength1),MA(C,MALength2));
> Sell = BarsSince(Buy)>=5;
> 
> Buy = ExRem(Buy,Sell);
> Sell=ExRem(Sell,Buy);
> 
> e = Equity();
> 
> Plot(C,"C",colorBlack,styleCandle);
> PlotShapes(Buy*shapeUpArrow+Sell*shapeDownArrow,
>     IIf(Buy,colorGreen,colorRed));
> 
> Plot(e,"equity",colorGreen,styleLine|styleLeftAxisScale,15000,18000);
> 
> //    The equity curve is choppy.
> //    If there are positive serial correlations
> //    between daily equity values, then we expect
> //    up days to be followed generally by more up days,
> //    and down days by more down days.
> //    So we might try applying a trend following system
> //    to the equity curve.
> //    When the equity curve is above its moving average,
> //    the system is working, and we should take trades.
> //    When the equity curve is below its moving average,
> //    the system is out-of-sync, and we should block trades.
> 
> //    EquityMALength is the lookback period for the equity
> //    curve moving average.
> //    We will set Pass to either 0 or 1.
> //    Pass==0 blocks trades, Pass==1 allows trades.
> 
> EquityMALength = Optimize("EquityMALength",12,1,20,1);
> 
> EquityMA = DEMA(e,EquityMALength);
> 
>
Plot(EquityMA,"equityMA",colorBrightGreen,styleLine|styleLeftAxisScale,15000,18000);
> 
> 
> Pass = IIf(e>=EquityMA,1,0);
> 
> Buy = Buy AND Pass;
> Buy = ExRem(Buy,Sell);
> Sell = ExRem(Sell,Buy);
> 
> e1 = Equity();
>
Plot(e1,"FilteredEquity",colorBlue,styleLine|styleLeftAxisScale,15000,18000);
> 
> /////////////////////////
> 
> When using the equity curve as a filter, you are applying a trading
system
> to a series.  If the series has a tendency to trend, then a
trend-following
> equity curve system will work.  If the series has a tendency to be mean
> reverting, then a mean reversion equity curve system will work.
> 
> The equity curve technique can be applied to either the daily
> marked-to-market equity, as in this example, or to the curve
resulting from
> treating each closed trade as a "bar."
> 
> The equity curve filter is usually set up to act as a filter to prevent
> entry when the system has not been performing well lately.  That is, it
> allows or prohibits entry, as in this example.
> 
> If the equity curve is monitored daily (or even intra-day), it can
act as an
> exit signal, causing an exit based on equity performance before the
other
> exit signals in the code.  Or, as in this example, it can just wait
for the
> exit logic in the base code to cause the exit.
> 
> So --- there are several options to try.  When you find something
useful,
> please post it back to this forum.
> 
> Thanks,
> Howard
> www.quantitativetradingsystems.com
> 
> 
> 
> 
> 
> On Mon, Apr 28, 2008 at 7:34 PM, droskill <droskill@xxx> wrote:
> 
> >   That's great - appreciate the references. Here's some code I came up
> > with - it doesn't work and I'm not sure why:
> >
> > ecurve = Foreign("~~~Equity","C");
> > ecurvema = MA(ecurve,50);
> > IIf(Ref(ecurve,-1)<Ref(ecurvema,-1),PosQty=10,PosQty=2);
> >
> > The basic idea here is to just change the number of positions based on
> > the whether or not the system equity is above or below a 50 day moving
> > average. However, in my testing, I can see that it never takes 10
> > positions. Now the system I'm trading easily goes above a 50 day
> > average - but clearly something isn't working. Is my approach totally
> > incorrect?
> >
> >  
> >
>



------------------------------------

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/