Building a Cross-Over Trading System

Investors often use moving averages to time their entry and exit into the markets. One of the most often used signals are the “Golden Cross” (for entry) and the “Death Cross” (for exit.)

The Golden Cross represents a major shift from the bears to the bulls. It triggers when the 50-day average breaks above the 200-day average. Conversely, the Death Cross restores bear power when the 50-day falls back beneath the 200-day.

The problem with most technical signals is that it requires you to inspect a chart of the stock you are interested in. However, with the StockViz API, you can automate just about every step of the process from checking for the cross-over to placing the trade.

Technical API

The StockViz Technical API for Equities (doc) gives you more that 50 technical stats to play with. Here’s how you access it in python:

unirest.get("https://stockviz.p.mashape.com/technicaldata/technicalsEquity",
     params={
          "symbol": ticker
     },
     headers={
          "X-Mashape-Authorization": mashape_auth,
          "Accept": "application/json"
     }
);

The result is a time-series in ascending order of dates. By comparing the last two elements, you can check if a cross-over occurred or not.

Accounts API

The StockViz Account API (doc) allows you to directly place trades through StockViz. These are “dummy” trades that update your portfolio. This allows you to track the performance of your investment strategy over a period of time.

Placing a trade is just another call to the API:

unirest.get("https://stockviz.p.mashape.com/account/OrderEquity", 
	params={
		"symbol": symbol,
		"qty": qty,
		"bs": buyOrSell,
		"t": "regular",
		"px": price,
		"asof": strTime
	},
	headers={
		"X-Mashape-Authorization": mashape_auth,
		"Accept": "application/json"
	}
);

Now all you have to do is run the script at the beginning of the day and you have your basic automated cross-over trading system. You can read the whole code here. The script runs the cross-over system for the NIFTYBEES ETF [stockquote]NIFTYBEES[/stockquote]

Note: You have to link your Mashape and StockViz accounts for the Accounts API to work (doc.)

Previously

Comments are closed, but trackbacks and pingbacks are open.