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

[amibroker] Custom metric help


  • Date: Thu, 03 Dec 2009 04:42:36 -0000
  • From: "jmdeacon" <jmdeacon@xxxxxxxxx>
  • Subject: [amibroker] Custom metric help

PureBytes Links

Trading Reference Links

I would like the backtest report to list what the total position size for a particular trade is.  I use a dynamic position size.  I have tried to modify my Custom Backtest code without success.  Prior to trying this, my custom code was set up to process entry signals first then scalein followed by exit signals.  When I try to add in the code for the custom metric, it just does not work.  Here is my latest attempt:

SetCustomBacktestProc(""); 
if( Status("action") == actionPortfolio ) 
{ 
 bo = GetBacktesterObject(); 
 bo.PreProcess(); 
 for( bar = 0; bar < BarCount; bar++ ) 
 {
  eqty = bo.Equity();
  //Handle ENTRY signals then Exit signals
  for ( sig=bo.GetFirstSignal(bar); sig; sig=bo.GetNextSignal(bar) ) 
  { 
   if( sig.IsEntry() && sig.Price != -1 ) 
   {  
    bo.EnterTrade( bar, sig.symbol, sig.IsLong(), sig.Price, 
    sig.PosSize, sig.PosScore );  
   }
   if (sig.Type == 5)	//  If signal type is scale-in
   {
    trade = bo.FindOpenPos(sig.Symbol);   //  Check for open position in stock
    if (trade)	
    {
    bo.ScaleTrade(bar, trade.Symbol, sig.IsLong(), sig.Price, 
    sig.PosSize, sig.PosScore ); 
    }
   }
  for (trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade())
    {					//  Loop through all closed trades
        Entry = trade.GetEntryValue();		//  Get trade entry in dollars       
        trade.AddCustomMetric("PosSize", Entry/eqty);	//  Calculate the position size of this trade
    }					//  End of for loop over all trades
   if (sig.IsExit() && sig.Price != -1 ) 
   { 
    bo.ExitTrade(bar,sig.symbol,sig.Price);  
   }
  }
  bo.UpdateStats(bar, 0); 
  bo.UpdateStats(bar, 1); 
  bo.UpdateStats(bar, 2); 
 } 
 bo.PostProcess(); 
}

I tried adding in bo.Backtest(True) and bo.ListTrades() but no matter where I put it, it would not run properly.

Any suggestions?

Thanks,

John



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

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

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:
    amibroker-digest@xxxxxxxxxxxxxxx 
    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/