PureBytes Links
Trading Reference Links
|
Jens,
Hope this helps
fe
// MONITOR PORTFOLIO EQUITY ROUTINE
// Equity Level is from Highest Equity since start of backtest
// OR from last 'Sell all' Signal
// this statement turns ON custom portfolio backtester procedure
SetOption("UseCustomBacktestProc", True );
Perc = 0.95; //Optimize("Perc",0.925,0.90,0.99,0.005);
if( Status("action") == actionPortfolio )
{
bo = GetBacktesterObject();
bo.PreProcess();
StoredEquity[0] = CurrentPortfolioEquity[0] = bo.InitialEquity;
for( bar = 1; bar < BarCount; bar++ )
{
CurrentPortfolioEquity[bar] = bo.Equity;
//determine the highest portfolio value
if( CurrentPortfolioEquity[bar] > StoredEquity[bar-1] )
{ storedEquity[bar] = CurrentPortfolioEquity[bar]; }
else
{ StoredEquity[bar] = StoredEquity[bar-1]; }
//this is low-level method to exit trades
//if yesterdays folio open equity is below perc %, ignore all at
todays open
if( CurrentPortfolioEquity[bar-1] < StoredEquity[bar-1]*perc )
{
StoredEquity[bar] = CurrentPortfolioEquity[bar]; //new equity level
//------------------------------------------------------------------------------
//ignore new buy signals
for ( sig=bo.GetFirstSignal(bar); sig; sig=bo.GetNextSignal(bar) )
{
if( sig.IsEntry() && sig.Price != -1 ) { sig.Price = -1; }
}
}//if portfolio value
bo.ProcessTradeSignals(bar);
}//for bar
bo.PostProcess();
}//if backtester
--- In amibroker@xxxxxxxxxxxxxxx, "tiedemj" <home@xxx> wrote:
>
> bump - still found no resolution on this...
>
> --- In amibroker@xxxxxxxxxxxxxxx, "tiedemj" <home@> wrote:
> >
> > Hello - trying to stop trading activity when portfolio equity is
> > below maxEquity by some pct, and resume trading when "equity" rises
> > above previous maxEquity (where "equity" is as if trading had not
> > been suspended)
> >
> > Using custom backttest as follows:
> >
> > // first run to collect when to stop/resume trading
> > bo.PreProcess();
> > for( bar = 0; bar < BarCount; bar++ )
> > {
> > bo.ProcessTradeSignals(bar);
> > ...some algorithm collecting when to stop/start trading
> > }
> > bo.PostProcess();
> >
> > // second run to do the actual trading with equity based
> stops/resumes
> > bo.PreProcess();
> > for( bar = 0; bar < BarCount; bar++ )
> > {
> > ...algorithm to scaleout/in of trades according to previous
> collected
> > info
> > bo.ProcessTradeSignals(bar);
> > }
> > bo.PostProcess();
> >
> > However, on the second call to bo.ProcessTradeSignals(bar) above, I
> > get "COM method/function failed: Internal application error". Can I
> > use custom backtest in this "reentrant" way? - or is there anothor
> > way to stop/resume trading based on portfolio equity (of the
> > underlying trading algorithm)...?
> >
> > best regards
> > Jens Tiedemann
> >
>
------------------------------------
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/
|