You are on page 1of 8

Venus United Lawrence H.

Klamecki, MBA
Technical Research September, 2003
www.venusunited.com V1.1.3

Building an Automated
End-of-Day Stock Trading
System Using Microsoft Excel
> Understand and apply proven technical indicators

> Create worksheets, files, and ranges

> Write technical indicator formulas

> Insert and use control buttons

> Write VBA macro code

> Build DDE data formulas using Quote.com’s QLink.exe

> Obtain and use free ASCII .TXT or subscription .CSV files

> Import price and volume data automatically

> Use the model to make trading decisions


Venus United Technical Research
September, 2003 www.venusunited.com V1.1.3

Table of Contents Introduction 3


Basic Technical Requirements 4
Using the Trading Model 4
A Primer: The Five Technical Indicators 5
Step 1: Average Directional Movement Index (ADX) 5
Step 2: Trending or Oscillating? 7
Step 2A: Trending = Moving Average Crossovers 7
Step 2B: Oscillating = Stochastic Oscillator 8
Step 3: Timing the Buy/Sell Signals with Bollinger Bands 10
Step 4: Enhancing Percentage Trade Success with the DMI 11
Setting Up 12
Building the Directory and File Structure 12
Building the Spreadsheet Structure 13
Building the Indicator Formulas 13
Market Data 13
ADX Indicator 14
Moving Averages 15
Stochastic 15
Bollinger Bands 15
DMI 16
Building the Macro Code 16
Step 1: Opening the Visual Basic Editor window 16
Step 2: Writing the Macro Code 17
Step 3: Checking the Code for Errors 21
Building the \Signals/ Sheet 21
Step 1: \Signals/ Sheet Labels and Formulas 21
Step 2: Build the Ranges 22
Step 3: Adding a Control Button and Assigning the Run_Model Macro 23
Building the Data Source File 25
Loading Data from Other Sources 27
Loading .CSV or .TXT Files 27
Getting FREE Historical Data from Yahoo! Finance 27
Running the Model on a Daily Basis 28
Macro Errors 28
Resource Appendix 29
Data Vendors 29
Microsoft Excel Programming Publications 30
Websites 30

© 2003 Venus United Building an Automated End-of-Day Stock Trading System Using Microsoft Excel 2
Venus United Technical Research
September, 2003 www.venusunited.com V1.1.3

Introduction The individual investor now has a wide array of specialized software packages to
choose from to focus on every tick, news byte, and chart formation for just about any
security. Most of these packages cost thousands of dollars, require you to pay extra for
real-time data feeds, and can require special courses or videos to learn how to operate.
While such software is generally quite sophisticated and flexible, it best suits the rapid-fire
day trader sitting in front of a computer screen all day long skimming eighths and quarters
out of the market. In other words, specialized trading software is not for most of us.

The less hyperactive individual investor has access to a wide assortment of tools
as well. These include email alerts, chat rooms, newspapers, websites, wireless pagers,
squawk-boxes, TV stations, streaming video, SEC documents, newsletters, desktop ticker-
tapes, elevator rumors, psychics, etc. In fact, the average investor has so much free infor-
mation at hand that it can take a full day to sort through it and make an actual investment
decision. Sure, almost all of these sources provide valuable information, but how do you
know when to buy and sell, or just hold when there is so much of it to sift through? What
really matters?

Individual investors often do poorly trying to trade short-term because information


overload and human emotions combine to produce irrational investment decisions. How-
ever, there is a very effective and cheap way to isolate the important information about
stock price, volume, and strength that can give you a distinct advantage in the markets,
regardless of whether you are a short-term or long-term investor. The answer is to build
your own automated trading model.

This report introduces you to the basics of building an end-of-day automated trad-
ing system using Microsoft Excel and daily data files. It covers technical requirements,
data feeds, importing data into Excel, spreadsheet management, data ranges, macros,
and formula-building. The system incorporates 5 basic time-proven indicators—the Aver-
age Directional Movement Index (ADX), moving average crossovers, stochastic oscillator,
Bollinger bands, and Directional Movement Indicator (DMI).

I will give you a brief overview of the technical indicators used in the system and
the functionality available in Excel. However, since this is a research report and not a
book, I assume that you can already operate a computer, work on the internet comfortably,
are familiar with Excel, and have read a thing or two about technical analysis.

If you have any comments or questions, please feel free to email me.

--Lawrence H. Klamecki
email: LHKlamecki@venusunited.com

© 2003 Venus United Building an Automated End-of-Day Stock Trading System Using Microsoft Excel 3
Venus United Technical Research
September, 2003 www.venusunited.com V1.1.3

Basic Technical This is what you’re going to need (feel free to upgrade—these are the minimum
Requirements requirements):

• 1 PC or laptop, with a 100MHz Pentium processor, 16+ Megabytes of RAM, 500


Megabyte hard drive, and a 56k modem, running Windows.

• Microsoft Excel 97 or later.

• A phone line (or DSL, satellite, or cable modem if you’re a speed freak).

• (Optional) A subscription to an end-of-day internet data service with a small DDE


or Active-X software program designed to import data directly into Excel spread-
sheets. I use Quote.com QCharts, which provides an excellent DDE link called
QLink.exe. QLink is free with a Quote.com subscription. See the Resources Ap-
pendix for other data vendors.

That’s it—that’s all you need. As you will see later, Excel is an exceptionally powerful and
flexible application that does most of the work for you. The fact that it comes pre-pack-
aged on most business PCs and laptops only means that we get a lot of great stuff for next
to nothing. Hey, we’re already thinking like smart investors, so let’s get started!

Using the Trading The trading model you will build does an excellent job of identifying profitable
Model trading opportunities and filtering out non-profitable, risky situations. However, it is crucial
to recognize that no system is infallible, and therefore you should not rely on the model
solely in making your investment decisions. Because the model is sometimes wrong
about the direction a stock is heading, it is very important that you combine the information
the trading model gives you with other market information, including fundamental analy-
sis, industry and company news, overall market direction, economic indicators, and your
own research. The trading model should be used as an additional important tool in your
arsenal, NOT a crutch to rely on in lieu of doing your normal investment homework. The
trading model is best used to identify potential opportunities and to time position entries
and exits.

You should also exercise sound portfolio management by holding a diversified


portfolio of at least 10 to 20 stocks (several mutual fund holdings of different types are
sufficient), holding long and short positions to hedge risk, and using leverage conserva-
tively.

Finally, avoid placing market orders prior to the opening since this is when most of
the price volatility occurs. Place limit orders instead, or just wait until 1 hour later when
volatility tends to drop. Time-average large position entries and exits over a few hours or
days. This obtains better prices over the long run. On the other hand, do not enter too
many small positions, or the increased transaction costs will eat away at any profits.

© 2003 Venus United Building an Automated End-of-Day Stock Trading System Using Microsoft Excel 4
Venus United Technical Research
September, 2003 www.venusunited.com V1.1.3

A good rule of thumb is to keep commissions at 1% or below. For example, if you pay
$9.95 per trade at your discount broker, you should buy and sell blocks of stock valued at
no less than $1000 at a time. Remember, too, that price slippage will eat away at your
profits if you trade frequently and in small amounts.

A Primer: The Five J. Welles Wilder invented the ADX indicator to help determine whether a particu-
Technical Indicators lar security (stock, bond, currency, fund, index, etc.) is moving in a trending mode or an
oscillating mode (often called range-trading, or swing-trading). This is a tremendously
Step 1: Average Directional useful indicator, not because it tells you when to buy or sell (which it doesn’t), but because
Movement Index (ADX)
it tells you which type of other indicator to use in a particular situation. Here’s an example:

TRENDING MODE: AT&T (T) 10-M inute Bars


51.5
51
50.5

In trending mode, prices climb 50


or drop in a staircase pattern 49.5
over time.
49
48.5
48

AT&T (T) ADX


50

40

30

20

10

As you can see from the graph of AT&T above, there is a clear downward
trend in price movement from left to right. As the trend continues, the ADX value in-
creases, showing the build-up in momentum until the trend itself begins to flatten.

© 2003 Venus United Building an Automated End-of-Day Stock Trading System Using Microsoft Excel 5
Venus United Technical Research
September, 2003 www.venusunited.com V1.1.3

Insert a New Code Module Once we have the Visual Basic Editor window open, we need to insert a new
code module to type in our macro code. Click Insert—Module and a new white Editor
window will suddenly open up named [Module 1 (Code)] on the top toolbar. This is
where you type the code.

Step 2: Writing the Macro Type the code exactly as follows in the blank Module 1 Editor window. If
Code you make an error, you will almost certainly have problems when you try to run the
macros! Be careful! The Visual Basic Editor does some of the work as you type, filling
in such things as the ( ) ellipses at the end of the “Sub” statements. If the Editor fills in
some of the required text, you do not need to type it a second time. The Editor will also
stop you if you have made certain typing errors or left out parts of the syntax.

Sub Run_Model ()
Call Signals
Call Save_File
End Sub

(code continued on next page)

© 2003 Venus United Building an Automated End-of-Day Stock Trading System Using Microsoft Excel 17
Venus United Technical Research
September, 2003 www.venusunited.com V1.1.3

Sub Signals()

' this macro grabs data, inserts into \Calculations/ sheet, calculates trading signals and
‘inserts them into \Signals/ sheet
Dim rowcount, colcount, datacol, datarow As Integer
Dim ticker, ADX, MA5, MA20, StochK, StochD, BollUpper, BollLower As Variant
Dim DMIup, DMIdn, price, signal As Variant
Workbooks("Model113.xls").Activate
Sheets("Signals").Select
For rowcount = 1 To Range("Data").Rows.Count
If Range("Data").Cells(rowcount, 1).Value = "" Then
Exit For
ElseIf Range("Data").Cells(rowcount, 1).Value <> "" Then
' assigns ticker variable and selects the data from the DATA.xls workbook
ticker = Range("Data").Cells(rowcount, 1).Value
'get stock data from DATA.xls workbook
If ticker = "" Then
Exit For
Else:
Workbooks("DATA.xls").Activate
'select correct sheet to get price data
If Left(ticker, 1) = "A" Or Left(ticker, 1) = "B" Or Left(ticker, 1) = "C" Then
Sheets("AC").Select
ElseIf Left(ticker, 1) = "D" Or Left(ticker, 1) = "E" Or Left(ticker, 1) = "F"
Then
Sheets("DF").Select
ElseIf Left(ticker, 1) = "G" Or Left(ticker, 1) = "H" Or Left(ticker, 1) = "I"
Then
Sheets("GI").Select
ElseIf Left(ticker, 1) = "J" Or Left(ticker, 1) = "K" Or Left(ticker, 1) = "L"
Then
Sheets("JL").Select
ElseIf Left(ticker, 1) = "M" Or Left(ticker, 1) = "N" Or Left(ticker, 1) = "O"
Then
Sheets("MO").Select
ElseIf Left(ticker, 1) = "P" Or Left(ticker, 1) = "Q" Or Left(ticker, 1) = "R"
Then
Sheets("PR").Select
ElseIf Left(ticker, 1) = "S" Or Left(ticker, 1) = "T" Or Left(ticker, 1) = "U"
Then
Sheets("SU").Select
ElseIf Left(ticker, 1) = "V" Or Left(ticker, 1) = "W" Or Left(ticker, 1) = "X"
Then
Sheets("VX").Select
ElseIf Left(ticker, 1) = "Y" Or Left(ticker, 1) = "Z" Then
Sheets("YZ").Select
End If

(code continued on next page)

© 2003 Venus United Building an Automated End-of-Day Stock Trading System Using Microsoft Excel 18
Venus United Technical Research
September, 2003 www.venusunited.com V1.1.3

These are Quote.com’s Bars


Wizard popup boxes required
to import real-time stock data
into your Excel worksheets.

Every time you run Model113.xls, you will also need to have DATA.xls open and
allow it to fully populate the price-volume data via an internet connect. The final result for
DATA.xls should look something like this:

© 2003 Venus United Building an Automated End-of-Day Stock Trading System Using Microsoft Excel 26

You might also like