Creating composite tickers of individual equity curves

Hi there,

I would like to create separate composite tickers of the equity curves for each futures market on a watchlist.
I am half-way there, but can’t quite get it working the way I would like with my average coding ability.
I am using mid-level CBT for the backtest and then adding these lines after the CBT:

eqp = Foreign("~~~EQUITY", "C");
AddToComposite( eqp, "~SingleEquity" + Name(), "X", atcFlagDeleteValues |atcFlagDefaults | atcFlagEnableInBacktest | atcFlagEnableInPortfolio );

This works OK if I select a single futures market and run a portfolio-level backtest on the current market. However, I would like to create tickers for about 40 markets, so manually selecting markets and running 40 backtests each time is a bit laborious.

I feel like there must be some way to do this using the “individual backtest” function and applying it to a watchlist containing all the markets, however, when I do this the composite tickers all return the same values (ie same equity curve). Not sure if this is a misunderstanding of AddtoComposite or ~~~EQUITY on my part (maybe both!), but either way, I can't figure it out.

Also, given the individual equity curves are already available in the report explorer when running an “individual backtest” on a watchlist, perhaps there’s some even more simple way for me to access them than creating my own composite tickers?

Any help would be greatly appreciated.

Thanks
Dan

The code for CBT incorrect. Foreign("~~~EQUITY", "C"); is available AFTER backtest, not while it is in the middle of backtesting.
For proper method see below.

Must-read for the start:

Then:
http://www.amibroker.com/kb/2006/03/11/how-to-create-copy-of-portfolio-equity/

Hi Tomasz,

Thanks for the reply and the links. I think perhaps I wasn't clear enough in my original email. I am using mid-level CBT rather than high-level for other purposes and don't want to change that. I am putting Foreign("~~~EQUITY", "C"); AFTER the CBT (I think) as below:

SetCustomBacktestProc("");
if( Status("action") == actionPortfolio )
{
 bo = GetBacktesterObject();
 bo.Preprocess();

    for (i = 0; i < BarCount; i++)	//  Loop through all bars
     {
     Some calculations here
     }

bo.PostProcess();	//  Do post-processing
}

eqp = Foreign("~~~EQUITY", "C");
AddToComposite( eqp, "~SingleEquity" + Name(), "X", atcFlagDeleteValues |atcFlagDefaults | atcFlagEnableInBacktest | atcFlagEnableInPortfolio   );

Hopefully that makes thing a bit more clear. If you still think the answer is in the links you sent, a little bit of a hint would be great before I re-read!

Thanks again for your help
Dan

Simply do as been posted at Knowledge base article by @Tomasz and do not use Foreign() but EquityArray.

Also in CBT you can't use Name() because it will return ~~~EQUITY name there!

So you can store Name() at status backtest and then pass to CBT.

SetOption("RefreshWhenCompleted", true);

// Store symbol to pass to CBT
if (Status( "action" ) == actionBacktest)
	StaticVarSetText("CBT_Symbol", Name());

// CBT
SetCustomBacktestProc( "", True );
if ( Status( "action" ) == actionPortfolio )
{
    /// http://www.amibroker.com/kb/2006/03/11/how-to-create-copy-of-portfolio-equity/
    /// @link https://forum.amibroker.com/t/creating-composite-tickers-of-individual-equity-curves/22085/4
    bo = GetBacktesterObject();
    //bo.Backtest();    

    bo.Preprocess();

    for (i = 0; i < BarCount; i++)
    {
        for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i) )
            if ( sig.IsEntry ) _TRACE(sig.Symbol);
      
        bo.ProcessTradeSignals( i );	
    }	

	bo.PostProcess();	
	
    _TRACE(Name());//Name() in CBT returns ~~~EQUITY !!!
    // Call symbol name
    nm = StaticVarGetText("CBT_Symbol");
    // Store Equity per symbol of individual backtest
    AddToComposite(bo.EquityArray, "~SingleEquity_"+nm, "X", atcFlagDeleteValues | atcFlagEnableInPortfolio );
}

// Dummy system
m = MA( Close, 20 ); 
Buy = Cross( Close, m ); 
Sell = Cross( m, Close );
Short = Cover = 0;

Now run individual backtest
16

And you will get n-times different individual Equity symbols with different Equity data.
15

Thanks so much fxshrat, works perfectly!

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.