Professional Documents
Culture Documents
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
> Obtain and use free ASCII .TXT or subscription .CSV files
© 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?
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):
• A phone line (or DSL, satellite, or cable modem if you’re a speed freak).
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.
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:
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
© 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
© 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
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