# How To Combine Equity Curves In Amibroker And Improve Trading System Performance

One of the keys to successful system trading is to be able to combine different strategies together. When you are able to combine less correlated strategies, it is possible to smooth drawdown, boost win rate and therefore improve your overall risk-adjusted returns.

In Amibroker it is possible to combine equity curves together so you can see what the advantages are.

Notice that in the first paragraph above I mention ‘less correlated’ instead of ‘uncorrelated’. That’s because it is rare to find profitable strategies that are completely uncorrelated. But so long as a system has a profitable edge and is slightly uncorrelated, great things can still be achieved.

## An Example Of Combining Trading Systems

As an example, consider two trading systems.

The first is a long-only stock system that follows trends. The second is a mean reversion short-only system. The table below shows the key statistics from each system on it’s own.

On the face of it, you would probably prefer to trade system 1 on it’s own since it has a higher annual return and a smaller drawdown than system 2.

However, when we combine the systems, we can see what would have happened if we had traded both systems at the same time (with equal amount of capital allocated to each).

As you can see, although our annualized return has decreased slightly, we have significantly reduced our maximum drawdown.

Our CAR/MDD ratio has now advanced to 1.03 indicating that combining the two systems leads to smoother, more consistent performance. As a result, we are likely to experience fewer losing streaks as well.

## How To Combine Equity Curves In Amibroker

Now that we have seen the benefits of combining trading systems we can look at how to combine equity curves in Amibroker and there are two main options available.

### Option 1 – AddToComposite Function

The simplest option is to use the Amibroker **AddToComposite** function to save the equity curves to a special ticker and then combine them together with another formula.

Bascially, every time Amibroker runs a back-test, it stores the equity of the trading system in a special ticker known as **“~~~EQUITY”**. This ticker gets re-populated every time a new back-test is run.

However, with the AddtoComposite function we can save the equity to any ticker name we like so that we can use it later on.

All you have to do is add the following code underneath your trading system rules and when you run a back-test your equity from that test will be saved to the new ticker called **“~~~MY_EQUITY_COPY”**.

// The code for AmiBroker 5.50 and above // YOUR TRADING SYSTEM HERE // .... SetCustomBacktestProc(""); if( Status("action") == actionPortfolio ) { bo = GetBacktesterObject(); bo.Backtest(); AddToComposite( bo.EquityArray, "~~~MY_EQUITY_COPY", "X", atcFlagDeleteValues | atcFlagEnableInPortfolio ); }

Here is the Amibroker page that explains it.

Once you have your equity curve saved as a symbol you can use it in various other ways and combine it with a different equity curve.

### An Example

For example, I ran two trading systems, one long and one short.

For the long trading system I saved the equity using the above formula as **“~MY_EQUITY_long**“.

For the short trading system I saved the equity as **“~MY_EQUITY_short”**.

**Note:** I could have chosen any name I wanted here such as **“SYSTEM_A”** or **“MY_SYSTEM”, **however, using ‘~’ at the beginning makes it easier to find the ticker in the symbol list.

Next, I opened up the formula editor and typed in the following code:

System1 = Foreign("~my_equity_long","Close"); System2 = Foreign("~my_equity_short","Close"); Combined = (System1 + System2) / 2; Plot(System1,"System1",colorgreen,styleline); Plot(System2,"System2",colorred,styleline); Plot(Combined,"Combined",colorBlack,styleline);

This formula simply adds the equity of system one to the equity of system two and then divides them by two.

Hit **Apply Indicator** and the formula plots all three equity curves in Amibroker as below:

As you can see, the black combined equity curve gives a lower return than system one but a smoother ride.

Now, to see the actual statistics of this combined system, all you have to do is run a buy-and-hold backtest on the two saved tickers.

To do this, I created a new watchlist called “**Combined**” and I added the tickers ~MY_EQUITY_long and ~MY_EQUITY_short.

Then I ran a simple buy and hold back-test on the new watchlist using another simple formula:

Buy = 1; Sell = 0;

In the backtest settings I set the number of open positions to two and I made the initial capital large enough that we can afford to buy both tickers.

**Note:** You may need to play around with your initial capital so that you have enough equity to buy both tickers and you will need to tick the box in the back-tester settings that disables trade size when there is no volume – because our equity tickers have no volume stored.

Now you can run the buy and hold back-test.

Make sure to split your starting capital equally between the two tickers (or however you want to allocate it) and the results will give a good representation of what would have happened if you had traded both of your two trading systems together.

**So to recap, here are the steps to take to combine equity curves in Amibroker:**

- Use the AddToComposite formula to save each equity curve to it’s own symbol
- Combine the two equity curves using the formula editor and plot on a chart
- Add the two equity curve symbols to a new watchlist
- Run a buy and hold strategy on the new watchlist

### Option 2 – Export To Excel

Option 1 is a nice and simple way to combine equity curves in Amibroker that works most of the time.

However, I have had some problems with this method when dealing with complicated trading strategies or when back-testing on a very large number of securities.

If you run into this problem too, there is a simple solution by exporting each equity curve to Excel. You can then combine the equity curves in Excel or re-import them back into Amibroker and then run a buy and hold system as before.

Here are the steps to take for this route:

### Step 1.

The first thing you’ll need to do is run your back-test and then export your quotes to a format that Excel will be able to read.

As I understand, there is no button that will do it all for you so the best thing to do is follow the steps listed on the AB website.

Basically, all you have to do is run an exploration on the equity ticker and export the quotes. So, after a back-test, open up the formula editor again and paste the following code:

Filter=1; AddColumn(O,"Open"); AddColumn(H,"High"); AddColumn(L,"Low"); AddColumn(C,"Close"); AddColumn(V,"Volume",1.0); AddColumn(OI,"Open Interest",1.0);

Click **Tools > Send to Auto-Analysis** and you will be ready to run this formula on any ticker you like.

Select the equity curve symbol **“~~~EQUITY”** then Click in the ‘**Apply To**‘ field and choose ‘**current symbol**‘ and choose **range: all quotations **or select the date range that you require.

Now hit **Explore** and Amibroker will deliver all the quotes as requested in the written formula above.

At this point you can click **File > Export CSV** or you can right click on the results, select all, then copy and paste them into Excel.

Once you have exported the equity quotes to Excel you can move on to the second trading system and do the same thing.

**Step 2.**

At this point you should have two CSV files containing system equity for two trading systems.

The first thing to do is to rename the tickers so you don’t get the two mixed up.

Now, you can either combine the two together in Excel or you can import them both back into Amibroker (as different tickers) using the import wizard.

Then you can add the two new tickers into a new watchlist and run a buy-and-hold test on the watchlist, just like in option one. You now have a way to see the results of combining trading systems together.

## 6 opinions

Tom

February 4, 2017

1:00 am

Both options are time-consuming and still don’t give a chance for optimal using of betsize based on combined equity.

The problem is that such option of joining the systems should be built-in without neccessity of making such combinations as described by you (thank you anyway).

JB Marwood

February 5, 2017

4:25 pm

I know what you mean. It would be nice to push a button and have it all done for us. Maybe in future versions. Option 1 is pretty quick though, once you have the formula saved.

Tom

February 7, 2017

2:12 am

It seems Tomasz Janeczko is very reluctant to add such option to Amibroker. At least I got such impression after reading Amibroker forum.

JB Marwood

February 10, 2017

10:09 pm

Yeah, well it’s up to him I guess.

Hardik

March 6, 2017

6:53 pm

Hii JB,

How do you allocate different percentages to systems. For example if I want to invest 70% in System 1 and 30 % in System 2 rather than 50/50 as shown in above example.

Thanks.

Hardik Upadhyay.

JB Marwood

March 7, 2017

2:24 pm

There is more than one solution.

One way, something like:

SystemA = Foreign(“SystemA”,”C”);

Positionsize = IIf(SystemA,-70,-30);

Another way, run the backtests individually – $7k in system A, $3k in system B (for 10k portfolio) then combine the curves.