Web Based Personal Stock Trading System Computer Science Essay

Published: Last Edited:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

Many people want to keep track of the stock market but cannot spend much time on it. They would like to trade according to their own strategy but not keeping an eye on it. With the system, users can setup their trading rules, then the system will follow the current market situation for them and evaluate if the criteria is satisfied or not periodically. Once the strike price of the selected stock is matched to the desired level, respond will be generate and notify the corresponding user.

The aim of this project is to develop a personal web-based stock trading system which enhances users to make decisions in stock trading, with emphasis on securities market in the Hong Kong.1.2 Objectives

1.2.1 Collect and update of financial information

The system will automatically gather and extract useful information from external resources, for example, HKEX and Yahoo Finance.

1.2.2 Stocks market analysis system

Users can analysis the stock market according to those predetermined and pre-programmed financial formulas.

1.2.3 Price alert system

The system will notify users if the current strike price of a particular stock reaches the one resulted from user-defined trading rules.

1.2.4 Indicator Interpreter System

An Indicator Interpreter System will be constructed to allow users to define their own indicators with their formula.

A short tutorial of how to use the system will be included in the project

1.3 Summary

This project develops a web-based system that consists of four main components: strategy builder for beginner user and advance user, strategy evaluation system and price alert system.

Different users can build their own strategy by strategy builders, then to evaluate their strategies by strategy evaluation system. The price alert system will help users to keep on track of the stock market by alerting users if a particular stock meets the requirement of a built strategy.

1.4 Structure of this report

Chapter 2: Project Background

This Chapter is a review of literature in this project. Technical analyzes and technical indicators including Moving Average,will be discussed. Also, the background and limitation of existing solution will be stated.

Chapter 3: Methodology

Chapter 4: Strategy Builder

Chapter 5: Strategy Evaluation System

Chapter 6: Price Alert System

Chapter 7: Conclusion

Chapter 8: Reference

Chapter 2 Project background

Hong Kong is one of the leaders of International Financial centre in the world. It has very strong cohesion with China. It is a door of China to the Asia and even the world.

In addition, the information sharing network in Hong Kong has being well developed.

"It was recognized on both sides of the negotiations that the territory's viability and future prosperity relied on retaining independence over a range of key fundamentals, including a separate and independent currency and monetary system that was at the foundation of Hong Kong's attraction as an international financial centre for the PRC and also for the rest of the Asian region"[1]

There is no doubt that stock is an essential element in our daily life. Even if you do not have any stock trading experience, you have to pay for the Mandatory Provident Fund (MPF), which is also classified as investment.

Most of people have to work or study in day time, they will not have much time to trace the change of the stocks. That is the reason for developing a web-based program to ease people's pain by helping to follow the changes of stocks. People no longer need to worry about the changes in stock during working or studying.

Although there is some software with similar functions available on the Internet, there still has room to construct the PSTS.

Some of them are so powerful but costly, for example, MetaStock.

On the other hand, some of them is free of charge but their function is insufficient, for example, JStock,which is a free software written in Java, its user interface for select indicators is not user-friendly. Users might found it is hard to use the software.

Also, the both of them require installation which may lower the portability of the software and convenience in usage.

2.1 Stock

What is stock?

The stock is the tool for the corporation to raise funds. It is broken into pieces of shares the corporations issue of shares and other ownership to collect enough capital for development of the comapies.

The shareholders gain or loss in stock price fluctuations. Some of stock, for example, the preferred stock, the shareholder does not have right for voting but can acquire a certain level of dividend payments.[2]

Stock is not the only one investment product. Why invest in stock?

Nowadays, time deposit rate of banks is terribly low. Most of them are far below 0.3% per annual. That means if you put $10000 in a bank for a year, you will get less than $30 as return. It is a price just enough for a meal. So, it is time to put money on more valuable investment methods.

"The best argument for owning stock is they're proven to be the best-performing investment over time"[3]( Paul Mladjenovic,)

2.2 Stock Market Analysis

How to make a wise decision on stock investment?

Analysis on stock's performance is essential for forecasting it price fluctuation.

For the purposed of analysis, there exists different kind of information worth to be referenced. In general, it can be classified into two categories, namely fundamental and technical.

2.2.1 Fundamental Analysis

The aim of fundamental analysis is to estimate the real value of the company including analyze historical and present data, for example, the financial statement like the balance sheet and profit & loss sheet.

Making financial forecast in fundamental analysis can be achieved by following methods.

1. Conducting a company stock valuation [6] which calculates companies' theoretical values and comparing it with current price of stock to predict the fluctuation of the stock price.

2. Calculating corporation's credit risk [4][5]

2.2.2 Technical Analysis

Technical analysis aims to forecast the movement of stock price by examining the historical data of the companies, for example, the market data like closing price, volume. [7]

How to analysis the stock technically? Technical indicators are typically used in the analysis process.

Technical Indicator

Technical indicators are used to predict the future price levels or the ordinary price direction by looking at past patterns of historical data. Examples of common technical indicators include Relative Strength Index, MACD and Bollinger Bands. These technical indicators are used for evaluating the performance of a particular stock. [8] Moving Averages

Moving averages (MAs) are trend following indicators that smoothing the price data. Although they do not predict price direction, they define the current direction. They help in smoothing price and filtering out the noise that has great difference with other price.

Simple Moving Average (SMA) and Exponential Moving Average (EMA) are the most common MA. Both of them can be used to determine the direction of trend.

It can be considered as an oversold condition when a SMA cross above the current price and overbought when SMA cross below current price. MA shows its significance in forming builder block for other indicators, for example, the MACD and Bollinger Bands.

[9] Moving Average Convergence-Divergence (MACD)

MACD is a momentum indicator which created by Gerald Appel .It uses moving average as building block. It can be computed by subtracting the longer moving average, for example, EMA with 26 days timeframe, from the shorter moving average, for example, EMA with 12 days timeframe. A signal line will be formed by a particular day timeframe of EMA or SMA; for example, EMA with 9 day timeframe, the recent changes in stocks' price can be outlined by using EMAs. Thus, by comparing EMAs of different periods, the MACD line shows changes in the trend of a stock. 

A buy or sell signal will be generated when MACD line crosses the signal line. Simply, It would be a overbought condition when MACD line cross below the signal line and oversold when MACD line cross above the signal line.[10][11] Relative Strength Index (RSI)

What Does Relative Strength Index - RSI Mean?

Relative Strength Index is a momentum oscillator which measures the speed and change of price movements. Its value has a range always between 0 and 100.

According to J. Welles Wilder who is the developer of RSI, It is an overbought condition when RSI is above 70 and oversold when RSI is below 30.

Beside look at the value of RSI to consider it is an overbought or oversold condition, the buy or sell signal can also generated by looking for divergences, failure swings and centerline crossovers.

According to Wilder, divergence between RSI and price action is an indication of a market turning point. There are two types of divergence, Bearish divergence and Bullish divergence; there is a Bearish divergence when price makes a new high but the RSI makes a lower high, thus failing to confirm. On the other hand, Bullish divergence exists when price makes a new low but RSI makes a higher low. [12][13]

In this project, the value of RSI will be focused on and 14 day timeframe which is typically used on RSI will be used in the strategy builder. Williams %R (%R)

Williams %R is a momentum indicator which is developed by Larry Williams. It shows the relationship between current closing price and the high and low of the past period.

%R has an oscillating range from 0 to -100.

It is considered to be an overbought condition when values are from 0 to -20. Values from -80 to -100 are considered to be oversold.[ 14]

With aid of fundamental and technical analysis, users can predict the trend of stock and easier to make a decision.

2.3 Existing solution

2.3.1 Existing software

MetaStock is software owned by a company which is named Thomson Reuters. It is a relatively powerful technical analysis tool. A product named 'MetaStockPro' which provide real time update has an Indicator Builder lets users write their own indicators.

Although MetaStock is so powerful, it is costly. Users have to pay a certain amount of fee per month in order to use the service. Also, it requires installation before used.[15] JStock

JStock is a free, open source and Java based software. It supports a simple and graphic based indicators builder. There is a great limitation for the user to create their own indicators by using this type of builder. Since the user do not know how to start using it. The software do not provide any free tutorial in using its function. Its builder starting with a blank page ,users do not know the way to use it.

But, this software provides as price alert function that prompt out alert through the Windows to alert users.

Same as MetaStock, this software require installation before use.[16]

Comparison between MetaStock, JStock and PSTS:

MetaStock is software with difference function but it is costly, users have to pay monthly fee.

JStock is open, free software with some valuable function but the function with certain limitation and not user-friendly enough.

Both of them are non web based. That means users have to install before use.

PSTS is a web based application, users can access to the system through the Internet. A computer with basic component, for example, Mozilla Firefox

Chapter 3 Methodology:

3.1 System architecture

MYSQL Database


Stock prices updating system



Data layer

Middle layer

Presentation Layer

The design of the system based on three-tier architecture approach. The database represents the data layer, which stores the data. The server represents the middle layer, which processes the command and functional operations, written in server language JSP. Finally, the user-interface represents presentation layer, which help the users communicate with the server.

For the stock prices updating system, which serves as the role of regular stock information update from the Yahoo! Finance

3.2 Collect and update of financial information

Programs will be written for gathering the historical data from external resources, such as Yahoo Finance.

Real-time data will also be collected for each specific time period, for example, 5-minutes, 15-minutes, hourly or daily basis.

Working flow of the data collecting

The historical data is stored in the servers of the web in comma-separated values (csv) format. Java program was written to downloading the file. Then, another Java program inserts the data into the database by reading the csv file.

Comparing to directly read the data and input into the database. This approach carries out a benefit that the Internet transmission speed will not directly affect the data insertion. Since the insertion process is relatively slow. If the Internet transmission rate is unstable, the data inputting process will become unstable and slow. If the whole csv file is download the directory of the local computer. The reading process will be more stable since it is regardless of Internet transmission speed and the web server of that site.

3.3 Database and server system

Databases and servers will be created and setup for supporting server side program and storing security information and trading records.

MYSQL and Tomcat will be used as database and server respectively.

Tomcat is a web server which typically used for Jsp pages, since it is relatively stable and reliable.

Database design

The data of a particular stock will be stored in a table in the database. Thus, the query and update operations can be carried out at a more effective way.

3.4 Language for developing the system

The user-interface, stock analysis system, and the alerting system will be developed by using html, JavaBeans, Servlets and JSP pages

The interaction between JavaBeans, Servlets and JSP pages:

The design of web application in this project is following the model-view-controller (MVC) architecture. The JSP pages is the user interface ,responsible for get user inputs and sending out request to the servlet.The servlets responsible to handle request and carried out simple logical operation. If the operation is complicated, the servlets will call the JavaBeans which responsible for more complicated logical operation to handle it.

With use of the architecture approach, the application is easier to maintain and update, for example, change in presentation layer will not affect the logical layer.

3.5 Price alert system

JavaMail is an API for Java to send mail and messages [17]. This project uses (Simple Mail Transfer Protocol) SMTP which is a common Internet standard for email transmission.

This project will use Gmail as SMTP server.

The work flow for using JavaMail

The user send their request though user interface to call the JavaBeans, the JavaBeans will connect to Gmail Server at particular port and email will be sent to the user if the condition set by user is satisfied.

Event flow of using the price alert system:

User set the condition to be alerted though the users interface. Then, the user interface will send requests to the price alert system to check in the condition is satisfied or not, the price alert system will have data access to the database and server and return the result to the user interface after that. The user Interface will return alert in form of email to the user if the condition if satisfied.

3.6 Technical Indicators implementation

Some of common technical indicators will be calculated and inputted into database as the backbone of the new strategies.

3.6.1 Moving Average

Simple moving average (SMA)


SMA is calculated by taking the average price of a stock over a period (N)

SMA: sum of price of that period /period

For example:

Daily closing price:10,11,13,14,12,11,13,15,15,16

SMA10 = (10 + 11+13+14+12+11+13+15+15+16)/10

SMA10 = 13

Exponential Moving Average (EMA)


The computation of EMA is based on the value of SMA when there has no previous value of EMA. Comparing to SMA, EMA apply more weight to recent prices. For this reason, weighting factors which decrease exponentially will be applied in computation of EMA

obtain the SMA

commutates the multiplier by following formula:

Multiplier = (2/ (period+1))

If there has no previous day of EMA :

Value of EMA = value of SMA

Else previous EMA exist

EMA = (Close price - EMA (previous day) )x multiplier + EMA(previous day)[18]

3.6.2 MACD


There are three steps to compute the MACD

obtain MACD line by find out the difference between 26 and 12 days EMAs

obtain the signal line which is the 9 days EMAs

Histogram which is the difference between the MACD line and signal line.[19]

3.6.3 RSI


The calculation of RSI start by obtains the RS which is the result of average gain over average loss.

RS = Average Gain / Average Loss

Average gain and loss can be found by the following formula:

Take 14 days timeframe as example:

Average Gain = [(Average Gain of previous days) x 13 + Gain of current day] / 14.

Average Loss = [(Average Loss of previous days) x 13 + Loss of current day / 14.

Then, the RSI can be computed by placing the RS in the following formula:

RSI = 100 -


3.6.4 William %R (%R)


For computing the %R, the highest high and the lowest low are needed.

Lowest Low = lowest low for the period

Highest High = highest high for the period

Take 10 days timeframe as example

Lowest Low = lowest low for the previous 10 days

Highest High = highest high for the previous 10 days [21]

Strategy Builder

Strategy in technical analysis can be defined as user defined formula to generate signals, both of sell or buy signals. Users can analysis the stock market according to those predetermined and pre-programmed financial formulas.

In order to build new strategies and manage the list of strategies, a user interface and database are needed. The user interface allows the user to create, edit, delete and save the indicators. It acts as the bridge of communication between the users and the system.

A database with historical data of the securities and calculated technical indicators is needed when the builders will call on the technical indicators or historical data, for example, the close price.

JavaBeans were written to read in the historical data from Yahoo! Finance which is an open and free resource. The read in data will be inputted into the database.

Based on the historical data inputted, the technical indicators can be calculated and inputted into the database.

3.7.1 Strategy Builder for beginner

Concerning on users who do not know any programming language, a simple and programming unrelated strategy builder was included on the system.

The basic unit in this builder is an expression which is constructed by a set of predefined value


Technical indicator




expression 2

Technical indicator



Cross above

For the above example, technical indicator is predefined value which it cannot be retyped but can be changed by selecting the drop down list which contains a set of indicators. In the other word, user can switch the RSI_14 to SMA_10 or other technical indicator provided by the system.

The operator and the condition is similar to technical indicator but the operand in condition1 is vary with other, a text field is provided for retyping the value to other numeric number, for example, 45.5.

expression 1 and expression 2 can be combined to a strategy by logical junction and/or.

At the beginning, users need to choose the type of strategy (buy/sell), then, they can start building their own strategy and the new strategy will be stored into a table of database. The stored strategy can be edited and deleted through the strategy management function.

3.7.2 Strategy Builder for Advance user

Due to the predefined values and the simplification of the strategy builder for beginner, a great restriction on creating strategy was observed. Strategy builder for beginner cannot satisfy the raising requirement of the advanced users who may have some knowledge on programming language.

In the initial stage of this part, users are allowed to edit any part of program which will create a new strategy. It is found that a big security risk and too complicated for users to handle the whole program.

For the above reason, most of program code is hidden from the user. Users can only program their strategy as expression shown below.

ema.calEMA(14) - ema.calEMA(12) < 6

The expression can be considered as three parts

Left hand side (LHS)

ema.calEMA(14) - ema.calEMA(12)



Right hand side (RHS)


Both LHS and RHS will be computed and inputted in the database for further used.

Illustration on the above example:

LHS: ema.calEMA(14)




EMA object created by the system

calEMA(int length)

Method of EMA class


Length of days

ema is the EMA object created in the hidden code, then the ema can call the method of the EMA class, for example, the calEMA(int length).

An API will be provided for the strategy builder for advanced user, It displays list of methods of different classes of technical indicators for users to build the strategy.

3.8 Strategy Evaluation System

How to know if the built strategies work on the real situation?

Strategy Evaluation System (SES) was developed for evaluating the strategy.

By the following steps, an evaluation report will be generated to show the result by applying the strategy to historical data of securities:

selecting the stock to be tested

selecting the buy and sell strategy to be tested

input the start date and end date

Then, an evaluation report will be shown

Content of the evaluation report:



Start date

Date filtered out by the buying strategy

End date

Date filtered out by the selling strategy


Gain or loss between the start date and end date

Will be calculated

Max gain

The maximum of gain within the period

Max loss

The maximum of loss within the period

Number of day gain

Number of day gain within the period

Number of day loss

Number of day loss within the period


Show if the strategy applied, users will gain or loss by applying it and its value

Event Flow of the strategy evaluation

The process of strategy evaluation started by getting users' input, including the stock code, start date and the end date of the period to be delaminated, the buying strategy and the selling strategy. Then, the system will filter out the starting point and the ending point within the period for the selected stock according the buy and sell strategy. When the starting point and ending point are located, the stock data, for example, the closing prices will be retrieved and used to generate the report.

Logon System

A logon system is needed for users to keep their piracy. A user can only view, edit and delete his/her own strategy and strategy from others is not visible. For simplification ,users will login with their email and password only.

3.10 Use Cases:


In this project, a web based trading system had been developed. Both of beginners and experienced users can build their own strategies though builder for beginners and builder for advance users. Users can also evaluate their strategies by the strategy evaluation system. The evaluated strategy can be used in the price alert system to keep user on track with the security market.

Chapter 4 Strategy Builder



Users have to login before using the system function.




Chapter 5 Strategy Evaluation System


Chapter 6 Price Alert SystemC:\Users\Cheong\Desktop\report\alert1.jpgC:\Users\Cheong\Desktop\report\alert3.jpg

Chapter 7 Conclusion

In this project, the main goal is to develop a web based system to allow users to create their own strategy for technical analysis purpose. So far, the system met the main goal to provide strategy builders for both beginners and advance users. Also, the strategy evaluation system provides an environment for users to evaluate their built strategy. A price alert system which has live feed of current price was set up to keep users' eyes closely on the securities market.

7.1 Limitation

The available technical indicators for user to build their strategy are not as many as some existing software, for example, the MetaStock.The more technical indicator available, the high flexibility for user to build their strategy.

Since the numbers of securities of Hong Kong is quite large, time for input historical data and calculate the technical indicators is terribly long.

The SMTP need to access particular port, if the port is blocked, for example, the wireless network of OUHK, the function of alerting system will be affected.

7.2 Future work

There are some addition functions to make the system more user friendly:

Addition works on Strategy Evaluation System:

Scanning the market to find the stocks that meet with the selected strategies. It is possible that no result will be generated when all of data in user selected stock do not satisfied the strategy. Also, it is troublesome for users to test each stock one by one, the scanning function may help user to filter out the stocks which they are searching

Summaries or comparison between different strategies. So far, there is no function available for comparison between different strategies. By comparison between different strategies, the differences in performance on different strategies can be observed and which strategies would perform better under same condition.

Moreover, an Indicator interpretation may be included in the system to help users to understand how to use with different indicators.

As mentioned above, the classes of technical indicators have various method. In order to use those method to build strategies, users have to learn some basic knowledge on it.

Considering that people will not sit on the chair and check the email all the time, alerting by sms may be a good idea to alert the user since most of user may switch on their mobile phone and carry it for most of time.

Users may find it is difficult to observe and compare the numeric data in the evaluation report. Plotting the data in form of chart may increase the visualization of the data. Google provides a service to plot the dynamic chart and it may be possible to include this function in this project.

Chapter 8 Reference

Anonymous, Rule of Hong Kong and relationship between China and Hong Kong

[1] http://ideas.repec.org/p/wef/wpaper/0021.html

Anonymous, Definition of stock, retrieved from

[2] http://en.wikipedia.org/wiki/Stock

Reason to invest in stock

[3] The unofficial guide to picking stocks / Paul Mladjenovic.

Foster City, CA: IDG Books Worldwide, c2001.

Anonymous, Definition of fundamental analysis, retrieved from

[4] http://en.wikipedia.org/wiki/Fundamental_analysis

Anonymous, Definition of fundamental analysis, retrieved from


Anonymous, Definition of stock valuation, retrieved from

[6] http://en.wikipedia.org/wiki/Stock_valuation

Anonymous, Definition of technical analysis, retrieved from

[7] http://en.wikipedia.org/wiki/Technical_analysis

Anonymous, Definition of technical indicators, retrieved from

[8] http://www.investopedia.com/terms/t/technicalindicator.asp

Anonymous, Definition of moving average, retrieved from

[9] http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:moving_averages

Anonymous, Definition of MACD, retrieved from

[10] http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:moving_average_conve

Anonymous, Definition of MACD, retrieved from

[11] http://en.wikipedia.org/wiki/MACD

Anonymous, Definition of RSI, retrieved from

[12] http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:relative_strength_in

Anonymous, Definition of RSI, retrieved from

[13] http://en.wikipedia.org/wiki/Relative_Strength_Index

Anonymous, Definition of Williams %R, retrieved from


Anonymous, Information about MetaStock, retrieved from

[15] http://www.equis.com/whc/MS11.aspx

Anonymous, Information about JStock, retrieved from

[16] http://jstock.sourceforge.net/features.html

Anonymous, Information about JavaMail, retrieved from



Anonymous, Formulation of moving average, retrieved from

[18] http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:moving_averages

Anonymous, Formulation of MACD, retrieved from


Anonymous, Formulation of Relative Strength Index, retrieved from

[20] http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:relative_strength_in

Anonymous, Formulation of Williams %R, retrieved from