Half way there. I think the code below will stop trading when your 
equity is down by 5%. But how do you resume trading when the equity 
(of the underlying trading system) goes back up again? What I'm 
trying to do is first calculate a "shaddow" equity as if all trades 
are taken regardless of equity situation - and then do the "real" run 
with stop/resume trading based on the previous calculated equity. 

Any ideas on how to achieve that?

(in an ideal situation, gain would remain the same, but dropdown 
would be less, thereby maximizing CAR/MDD)

--- In [email protected], "oceanchimes" <[EMAIL PROTECTED]> 
wrote:
>
> 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 [email protected], "tiedemj" <home@> wrote:
> >
> > bump - still found no resolution on this...
> > 
> > --- In [email protected], "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
> > >
> >
>


Reply via email to