PureBytes Links
Trading Reference Links
|
Thanks for the code. Simpler and easier to follow.
Is there a way to report out what date the MaxFlat occurred? I played
around with trying to use DateTime() but when I put it in
bo.AddCustomMetric, the result was blank?
Thanks,
John
--- In amibroker@xxxxxxxxxxxxxxx, ftonetti@xxx wrote:
>
> SetCustomBacktestProc("");
> if (Status("action") == actionPortfolio)
> {
> bo = GetBacktesterObject();
> bo.Backtest();
> Eqty = Foreign("~~~Equity", "C");
> MaxEq = Highest(Eqty);
> FlatEq = BarsSince(MaxEq > Ref(MaxEq,-1));
> MaxFlat = LastValue(Highest(FlatEq));
> bo.AddCustomMetric("Max Flat Eq Bars", MaxFlat);
> }
>
> ----- Original Message -----
> From: jmdeacon
> Date: Sunday, November 23, 2008 8:03 pm
> Subject: [amibroker] Addcustommetric for length of drawdown
> To: amibroker@xxxxxxxxxxxxxxx
>
> > I am having trouble getting my code to output to me the length
> > of the
> > drawdown from portfolio equity high to the next equity high.
> > Everytime I run the backtest, the report always list MaxDDdays =
> > 0.
> > Any help would be appreciated.
> >
> > Thanks,
> >
> > John
> >
> > //Entry signals before sell signals
> > //Calculate length of drawdown
> > SetCustomBacktestProc("");
> > if( Status("action") == actionPortfolio )
> > {
> > bo = GetBacktesterObject();
> > Eqty = bo.Equity();
> > Cash = bo.Cash();
> > MaxEqty = bo.InitialEquity();
> > DDdays = 0;
> > MaxDDdays = 0;
> > bo.PreProcess();
> > for( bar = 0; bar < BarCount; bar++ )
> > {
> > //Handle ENTRY signals
> > for ( sig=bo.GetFirstSignal(bar); sig;
> > sig=bo.GetNextSignal(bar) )
> > {
> > if( sig.IsEntry() && sig.Price != -1 )
> > {
> > //determine if cash is less than 10% of equity, if so, do not
> > enter trade
> > if( Cash> {
> > sig.Price = -1;
> > }
> > else
> > {
> > bo.EnterTrade( bar, sig.symbol, sig.IsLong(), sig.Price,
> > sig.PosSize, sig.PosScore );
> > }
> > //calculate the length of the drawdown from portfolio equity high
> > to next portfolio equity high
> > if (Eqty> {
> > DDdays = DDdays+1;
> > if (DDdays>MaxDDdays) //Is this a new max for length of drawdown?
> > {
> > MaxDDdays = DDdays; //reset to a new MaxDDdays
> > }
> > }
> > else
> > {
> > MaxEqty = Eqty; //Since today is a new equity high,
> > increase the
> > MaxEqty to todays equity
> > DDdays = 0;
> > }
> > }
> > }
> > bo.UpdateStats(bar, 0);
> > bo.UpdateStats(bar, 1);
> > //handle EXIT signals
> > for ( sig=bo.GetFirstSignal(bar); sig;
> > sig=bo.GetNextSignal(bar) )
> > {
> > if (sig.IsExit() && sig.Price != -1 )
> > {
> > bo.ExitTrade(bar,sig.symbol,sig.Price);
> > }
> > }
> > //update stats after closing trades
> > bo.UpdateStats(bar, 2);
> > }
> > bo.PostProcess();
> > bo.addcustommetric("MaxDDdays",MaxDDdays);
> > }
> >
> >
> >
>
------------------------------------
**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
*********************
TO GET TECHNICAL 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/
|