In this post I will show how to build a quick trading system for the Nifty, the Indian stock exchange, using Amibroker. The purpose of this isn’t to provide a working trading system but to illustrate how easily it can be done. The video here proves just how quick the process can be.

Building a Nifty positional trading system

Position trading is all about taking relatively long-term, directional trades in the market. Therefore, to build this system I first considered what type of strategies would fit the bill. Since the Nifty is the main index for the Indian stock market it’s highly liquid and tends to exhibit strong trending properties. I decided that a moving average strategy might be a good one to use.

Step 1

The first step is to download Amibroker and Amiquote to the computer and both can be downloaded on a free trial. While Amibroker is the software used to test strategies, Amiquote is used to import free historical data into the program.

Step 2

When Amibroker first opens, the default database and template is pre-loaded. (A new database can be setup but in this instance I will just keep open the preloaded one – this contains financial information for the 30 stocks in the Dow Jones Industrial Average.)

What we want to do is upload historical data for the Nifty so that we can test various strategies and this is easily done with Amiquote.

Simply open up Amiquote and click the yellow cross ‘Add tickers’ button. Then type in the Yahoo! ticker symbol for the Nifty which is ^NSEI.

Set the dates for the download, make sure the source is set to Yahoo Historical and then click the green ‘play’ button to download the data.

Step 3

So long as Amibroker is open in the background historical data for the Nifty will be automatically imported into the program. Look over to the symbol panel on the left and you’ll find ^NSEI at the top. Click on it and the data will be displayed in the main chart. (You can drag any indicators such as moving averages over from the technical indicators panel straight onto the chart and it will display it.)

Step 4

I want this Nifty positional trading system to find profitable trends using moving averages so now I will test my ideas using the back-tester.

I still prefer to use the old back-tester so I click over to Analysis > Old Automatic Analysis. This brings up the analysis window. Here, I click Edit in order to open up the example trading code that comes pre-loaded.

Step 5

To create a new system I simply delete what’s already there and start writing in my own code.

I have decided that this positional trading system will buy the Nifty when the 100 day EMA crosses over the 250 day EMA and sell when it crosses back under. The system will use the close to calculate values and use the open to enter and close trades. The exact code is shown here:

SetTradeDelays(1,1,1,1);
EMAfast = EMA(C,100);
EMAslow = EMA(C,250);
Buy = Cross(EMAfast,EMAslow);
Sell = Cross(EMAslow,EMAfast);
BuyPrice = O; SellPrice = O;

Note: the system uses trade delays to ensure signals are entered on the next open and not the previous open. The system also uses 100% cash available to take positions and commissions (refined using the settings tab in the Analysis window) are set to 0.05% per trade.

Next it is important to verify the syntax is correct by clicking on the red tick. I then give the system a name and close the window making sure to save changes.

Step 6

Now that the code has been written, I simply re-pick the formula file which has been saved into the Amibroker folder on my computer.

Under ‘Apply to’ I tick current symbol (^NSEI) and under dates I choose the 1/1/2007 to the 1/1/2011. I then click back test and Amibroker gets to work.

Step 7

It takes Amibroker less than a second to perform the back test and the system’s results are clearly indicated on the bottom of the analysis window. Clicking on Report allows a much more in depth view of the systems results.

Nifty positional trading system results

As you will see by the results, only one trade was placed producing a compound annual return of 11.90% with a maximum system drawdown of -11.25%.

I then re-run the system on forward data, from 2011 to the present day and see whether the system performed was able to replicate those results.

Conclusion

As you can see, building a Nifty positional trading system is incredibly simple with Amibroker and the free data from Yahoo. While these results on the Nifty may not sound that great, they are actually not bad. Considering that the system produced just one trade in both periods, the risk per trade is OK and the CAR/MDD metric is decent too.

Using this strategy on a number of other markets together and incorporating some more rules could lead to a worthwhile trend system.


 

Tags: , , , ,


Leave a Reply

%d bloggers like this: