{"id":1922221,"date":"2014-02-19T12:14:19","date_gmt":"2014-02-19T06:44:19","guid":{"rendered":"http:\/\/stockviz.biz\/index.php\/?p=1922221"},"modified":"2014-02-19T12:14:19","modified_gmt":"2014-02-19T06:44:19","slug":"building-cross-trading-system","status":"publish","type":"post","link":"https:\/\/stockviz.biz\/index.php\/2014\/02\/19\/building-cross-trading-system\/","title":{"rendered":"Building a Cross-Over Trading System"},"content":{"rendered":"<p>Investors often use moving averages to time their entry and exit into the markets. One of the most often used signals are the &#8220;Golden Cross&#8221; (for entry) and the &#8220;Death Cross&#8221; (for exit.)<\/p>\n<p>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.<\/p>\n<p>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.<\/p>\n<h3>Technical API<\/h3>\n<p>The StockViz Technical API for Equities (<a title=\"stock technicals\" href=\"https:\/\/www.mashape.com\/drona\/stockviz#!endpoint-Equity-Technicals\" target=\"_blank\">doc<\/a>) gives you more that 50 technical stats to play with. Here&#8217;s how you access it in python:<\/p>\n<p><small><\/p>\n<pre>unirest.get(\"https:\/\/stockviz.p.mashape.com\/technicaldata\/technicalsEquity\",\r\n     params={\r\n          \"symbol\": ticker\r\n     },\r\n     headers={\r\n          \"X-Mashape-Authorization\": mashape_auth,\r\n          \"Accept\": \"application\/json\"\r\n     }\r\n);<\/pre>\n<p><\/small><\/p>\n<p>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. <\/p>\n<h3>Accounts API<\/h3>\n<p>The StockViz Account API (<a href=\"https:\/\/www.mashape.com\/drona\/stockviz#!endpoint-Portfolio-Equity\" title=\"StockViz trading API\" target=\"_blank\">doc<\/a>) allows you to directly place trades through StockViz. These are &#8220;dummy&#8221; trades that update your portfolio. This allows you to track the performance of your investment strategy over a period of time. <\/p>\n<p>Placing a trade is just another call to the API:<\/p>\n<p><small><\/p>\n<pre>unirest.get(\"https:\/\/stockviz.p.mashape.com\/account\/OrderEquity\", \r\n\tparams={\r\n\t\t\"symbol\": symbol,\r\n\t\t\"qty\": qty,\r\n\t\t\"bs\": buyOrSell,\r\n\t\t\"t\": \"regular\",\r\n\t\t\"px\": price,\r\n\t\t\"asof\": strTime\r\n\t},\r\n\theaders={\r\n\t\t\"X-Mashape-Authorization\": mashape_auth,\r\n\t\t\"Accept\": \"application\/json\"\r\n\t}\r\n);<\/pre>\n<p><\/small><\/p>\n<p>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 <a href=\"https:\/\/github.com\/shyams80\/StockViz\/blob\/master\/equity\/01-simple-ma\/simple-ma.py\" title=\"simple cross-over based model\" target=\"_blank\">here<\/a>. The script runs the cross-over system for the NIFTYBEES ETF [stockquote]NIFTYBEES[\/stockquote]<\/p>\n<p><strong>Note:<\/strong> You have to link your Mashape and StockViz accounts for the Accounts API to work (<a href=\"http:\/\/stockviz.biz\/index.php\/2014\/02\/17\/linking-mashape-stockviz-accounts\/\" title=\"linking mashape and stockviz\" target=\"_blank\">doc<\/a>.)<\/p>\n<h6>Previously<\/h6>\n<ul>\n<li><a href=\"http:\/\/stockviz.biz\/index.php\/2014\/02\/17\/stockviz-api\/\" target=\"_blank\">The StockViz API<\/a><\/li>\n<li><a href=\"http:\/\/stockviz.biz\/index.php\/2014\/02\/18\/api-samples-github\/\" title=\"API Samples on GitHub\" target=\"_blank\">API Samples on GitHub<\/a><\/li>\n<li><a href=\"http:\/\/stockviz.biz\/index.php\/2014\/02\/18\/news-reading-sentiment-analysis-app\/\" title=\"hack your own news reading app\" target=\"_blank\">Build your own News Reading and Sentiment Analysis App<\/a><\/li>\n<li><a href=\"http:\/\/stockviz.biz\/index.php\/2011\/08\/17\/the-golden-cross-and-the-death-cross\/\" title=\"Golden-cross and Death-cross explained\" target=\"_blank\">The Golden Cross and the Death Cross<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Investors often use moving averages to time their entry and exit into the markets. One of the most often used signals are the &#8220;Golden Cross&#8221; (for entry) and the &#8220;Death Cross&#8221; (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 &hellip; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3131,9],"tags":[3161],"class_list":["post-1922221","post","type-post","status-publish","format-standard","hentry","category-api","category-your-money","tag-api-technical","entry"],"_links":{"self":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/posts\/1922221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/comments?post=1922221"}],"version-history":[{"count":0,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/posts\/1922221\/revisions"}],"wp:attachment":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/media?parent=1922221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/categories?post=1922221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/tags?post=1922221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}