Automated Stock Trading System - SpreadsheetML

Creating an Automated Stock Trading System in Excel

Automated Stock Trading System



Copyright (c) 2008-2018, ConnectCode Pte Ltd. All Rights Reserved. ConnectCode accepts no responsibility for any adverse affect that may result from undertaking our training. No statements in this document should be construed or thought to represent investment advice of any type since the sole purpose of the explanation is to illustrate the technique. Microsoft and Microsoft Excel are registered trademarks of Microsoft Corporation. All other product names are trademarks, registered trademarks, or service marks of their respective owners

Table of Contents

1.

Introduction ................................................................................................................................. 2

2.

Download Stock Trading Prices ............................................................................................... 3

2.1 Download Data from Yahoo Finance .............................................................................. 3

2.2 Automating the download of Stock Prices ...................................................................... 4

3.

Moving Average Trends ............................................................................................................. 7

3.1 Simple Moving Average .................................................................................................. 7

3.1.1 10 Days Moving Average................................................................................... 7

3.1.2 14 Days Moving Average................................................................................... 8

3.1.4 Charting the Moving Average ............................................................................ 8

3.2 Using the Moving Average .............................................................................................. 9

3.3 Wilders Moving Average ................................................................................................. 9

3.4 True Range .................................................................................................................... 10

3.5 Average True Range ..................................................................................................... 11

3.6 Directional Movement.................................................................................................... 12

3.7 Directional Movement Indicator .................................................................................... 14

3.7.1 Positive/Negative Directional Movement Indicator ......................................... 15

3.8 Average Directional Movement Index........................................................................... 16

3.9 Using the Indicators ....................................................................................................... 17

4.

What Next?................................................................................................................................ 4-1

Pg ii Automatic Download of Stock Quotes

Version 1.1

1. Introduction

The aim of this course is to allow you to use the various Stock Technical Indicators and create an Automated Stock Trading System using Microsoft Excel. We assume that you have some basic knowledge of Excel and is interested in putting into practice the financial concepts of a technical stock trading system. We will start from downloading Stock data and move into the calculation of the different Technical Indicators. The Technical Indicators include Moving Average, Directional Movement, Directional Movement Indicator, Average Directional Movement Index and Average True Range. The focus is on two aspects. The first is the understanding of the specific Technical Indicators and the second is the implementation of the indicators in Excel. We do not guarantee that you will get rich by going through these materials but we are confident that you will become a better technical trader as you will be able to apply many of these Technical Indicators to analyse your portfolio.

Pg 2-2 Creating an Automated Stock Trading System

Version 1.1

2. Download Stock Trading Prices

2.1

Download Data from Yahoo Finance

Launch your browser and navigate to . Search for the stock you require by entering the stock quote, such as "'BAC", into the search bar. Click on the "Historical Data" link and then the "Download Data" link as shown.

When prompted, click on "Open" to download the data to Excel. You should see the following stock data in Excel.

Pg 2-3 Creating an Automated Stock Trading System

Version 1.1

2.2

Automating the download of Stock Prices

The methods above are useful when you are exploring what kind of data to download to Excel. However, it will be laborious to go through all the steps to download the price of a specific Stock symbol. This section will show you how to automate the download of the Stock Prices. We will be using a simple programming language called Visual Basic for Applications (VBA). If you will like to find out more about VBA, you will be interested to know that offers a VBA course on our website. Otherwise, please be assured that we will be going through the steps, one at a time to allow you to construct the models without prior knowledge of VBA.

Launch Excel and create a new workbook. Call this workbook AutomatedDownloadData.xls.

In Microsoft Excel 2003: Go to Tools->Macro->Visual Basic Editor

In Microsoft Excel 2007: Go to Developer->Visual Basic

Right click on VBAProject (your Excel Filename) and select Insert->Module. A default "Module1" will be inserted. Click on Module1 and paste the VBA code below on the right-hand side of the Visual Basic Editor. The following VBA codes allow you to download data from Yahoo Finance based on a specified Stock symbol, Start Date and End Date.

Sub GetStock(ByVal stockSymbol As String, ByVal StartDate As Date, ByVal EndDate As Date)

On Error GoTo ErrHandler:

Dim freq As String

Dim crumb

As String

Dim cookie

As String

Dim response

As String

Dim strUrl As String

Dim DownloadURL As String

Dim period1, period2 As String

Dim httpReq As WinHttp.WinHttpRequest

Set httpReq = New WinHttp.WinHttpRequest

freq = "1d"

DownloadURL = "" & stockSymbol With httpReq

.Open "GET", DownloadURL, False .setRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8" .send .waitForResponse response = .responseText cookie = Split(.getResponseHeader("Set-Cookie"), ";")(0) End With

period1 = (StartDate - DateValue("January 1, 1970")) * 86400 period2 = (EndDate - DateValue("January 1, 1970")) * 86400 Dim counter As Long Dim startCounter As Long Dim result As String Dim dataResult As String Dim startResult As String

Pg 2-4 Creating an Automated Stock Trading System

Version 1.1

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download