Ed, Thanks I am finding issues with my Low Level code ... it is not giving me same results with normal Backtest. Will work on those first then get back and try your code again
Ara ----- Original Message ----- From: Edward Pottasch To: [email protected] Sent: Thursday, September 25, 2008 12:16 PM Subject: Re: [amibroker] Backtest - Number of positions hi Ara, this is low level code. You need to put the code in a file. Then call this file in your higher level AFL code by placing SetCustomBacktestProc() at the top of your code. For instance it could look like: SetCustomBacktestProc( "C:\\Amibroker Programs\\myAFL\\CustomBacktest\\balancing\\balancingMinPositions_cbi.afl" ); If you have more than one low level file you need to call in your higher level code then that is not possible (as far as I know). That's why I usually stuff them all in 1 file. regards, Ed ----- Original Message ----- From: Ara Kaloustian To: [email protected] Sent: Thursday, September 25, 2008 8:57 PM Subject: Re: [amibroker] Backtest - Number of positions Ed, Thanks for the code to count trades ... I tried using it, but am running into conflicts and screwy results because I need to use Low Level CBI for signal processing reasons. Would this code be adaptable with Low Level? How? ... or am I doing something wrong? I placed the code at several locations, without any success of good results. Thanks Ara ----- Original Message ----- From: Edward Pottasch To: [email protected] 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 ----- From: Ara Kaloustian 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
