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

Re: [amibroker] Backtest - Number of positions



PureBytes Links

Trading Reference Links

Ed,
 
Thanks again ... appreciate your sharing
 
Will try it next week ... after some MUST DO chores ...
 
A
----- Original Message -----
Sent: Wednesday, September 03, 2008 12:20 PM
Subject: Re: [amibroker] Backtest - Number of positions

you can try it out by putting the code in a file  (for instance: findNumberOfLongAndShortPositions_cbi.afl)  and then call this file in your main program like:
 
SetCustomBacktestProc( "C:\\Amibroker Programs\\myAFL\\CustomBacktest\\loop through trades\\findNumberOfLongAndShortPositions_cbi.afl" );
Then do a backtest as you normally do and you can chart the results using for instance:
 
SetChartOptions(0, chartShowDates);
GraphXSpace = 0;
 
ltrades = Foreign("~longTrades","C");
strades = Foreign("~shortTrades","C");
Plot(strades,"Short Trades",colorRed,styleLine);
Plot(ltrades,"Long Trades",colorBrightGreen,styleLine);
PlotOHLC( ltrades, ltrades, 0, 0, "", colorBrightGreen, styleCloud );
PlotOHLC( strades, strades, 0, 0, "", colorRed, styleCloud );
 
I assume that you are doing a portfolio type backtest,
 
rgds, Ed
 
 
 
----- Original Message -----
Sent: Wednesday, September 03, 2008 8:39 PM
Subject: Re: [amibroker] Backtest - Number of positions

Thanks Ed,
 
I have not got to CBT yet ... but on my list
 
Ara
----- Original Message -----
Sent: Wednesday, September 03, 2008 11:00 AM
Subject: Re: [amibroker] Backtest - Number of positions

Ara,
 
I did this a while back. I extracted this information by looping through the trades using the CBT. Then I saved the info in a composite. Added code below. You just need to call this code inside your main program using SetCustomBacktestProc( ) but I think you know the drill:
 
rgds, Ed
 
 
SetCustomBacktestProc("");
 
if( Status("action") == actionPortfolio ) {
  
 bo = GetBacktesterObject();
 
 // perform default portfolio backtest
 bo.Backtest();
 
 // initialisations
 longTrades = 0;
 shortTrades = 0;
 
 // store the DateTime() in a STRING array.
 fdatetime = DateTime();
 
 // loop through trades 
 for( trade = bo.GetFirstTrade(); trade ; trade = bo.GetNextTrade() ) {
           
  // find the entry datetime of the trade
  entry_datetime = trade.EntryDateTime;
 
  // find the exit datetime of the trade
  exit_datetime = trade.ExitDateTime;
  
  // locate the array index at entry
  index_entry = IIF(entry_datetime == fdatetime, 1, 0);
  
  // locate the array index at exit
  index_exit = IIF(exit_datetime == fdatetime, 1, 0);
  
  // indicate bars where the trade occurs
  index_trade = flip(index_entry,index_exit);
  
  // accumulate long and short trades
  if (trade.IsLong) {
     
   longTrades = longTrades + index_trade;
 
  //} else if (!trade.IsLong) {
  } else {
  
   shortTrades = shortTrades + index_trade;
 
  }  
 
    
 }  
 
 
 // loop through open positions
 for( Openpos = bo.GetFirstOpenPos(); Openpos ; Openpos = bo.GetNextOpenPos() ) {
   
  // find the entry datetime of the trade
  entry_datetime = Openpos.EntryDateTime;
 
  // find the exit datetime of the trade
  exit_datetime = Openpos.ExitDateTime;
  
  // locate the array index at entry
  index_entry = IIF(entry_datetime == fdatetime, 1, 0);
  
  // locate the array index at exit
  index_exit = IIF(exit_datetime == fdatetime, 1, 0);
  
  // indicate bars where the trade occurs
  index_trade = flip(index_entry,index_exit);
  
  // accumulate long and short trades
  if (Openpos.IsLong) {
  
   longTrades = longTrades + index_trade;
 
  //} else if (!Openpos.IsLong) {
  } else {
  
   shortTrades = shortTrades + index_trade;
 
  }  
 
    
 }  
 
 AddToComposite(longTrades,"~longTrades","C",atcFlagDeleteValues | atcFlagEnableInPortfolio );
 AddToComposite(shortTrades,"~shortTrades","C",atcFlagDeleteValues | atcFlagEnableInPortfolio); 
  
}
 
 
 
 
 
----- Original Message -----
To: AB-Main
Sent: Wednesday, September 03, 2008 7:39 PM
Subject: [amibroker] Backtest - Number of positions

Is there a way to determine (get a chart) of the number of positions over time
 
Tx
 
Ara

__._,_.___

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




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___