Introduction

This is page intended to help anyone that wants to participate in the development of jStock.

As my computer is fast enough (Athlon XP 2500 with 1 gig of RAM, I have not used a lot of time to optimise the speed and/or memory used by jStock. Earlier versions of jStock ran well on a PII with 192 MB RAM, I don't think use of resource has exploded since then. Oh, btw I use Linux only at home, but I try the applications once in a while on the W2K laptop I (have to) use at work, and it seems to work ok.

Classes in jstock (not complete yet)

UML class diagram

This class diagram is generated by the Eclipse UML plugin and may give an overview of the relationship between the classes. It is very out of date and will remain so until the free edition of Eclipse UML plugin is updated with support for Eclipse 3.0.

jStock

This is, as the name suggest, the main class. It is responsible for the most of the user interface and also have a Hashmap with stocks that is already drawn.

However when the user wants a new chart drawn, that task is left to ChartPanel.

ChartPanel

ChartPanel takes care of requesting data for the particular stock from the kind and helpful class ChartData. When the data is delivered it checks with the userPreferences and decides how the chart area should be partioned. The actual drawing of the chart is left to CandleStickPanel class.

CandleStickPanel

If this application has a workhorse this is it. Although it gets a lot more help than in earlier versions, the important parts of the application still is computed here. Based on the size of the screen the number of sticks to be drawn is found, X and Y axis is drawn, and finally the size and position of candlesticks themself are computed and drawn. And if the windows is resized it happens all over again.

Indicator Interfaces or howto write new indicators

Introduction

The whole idea behind the interfaces for the indicators was that it should be possible to write a new indicator without changing one line of the existing code (and that includes the fields in the "Options" menu where users can change indicators parameters).

The interfaces,IndicatorInterface and IndicatorParametersInterface, can be found in the package com.exponto.jstock.indicators together with the indicators I have implemented.The defined methodes are fairly well (at least compared with the rest) documented in Java doc.

The interfaces allows for to types of indicators, either drawn together with the candlestick panel or drawn in a separate panel. Both types can either be enabled or disabled, dependant of user input.

Be aware of the the candlestick panel uses a logaritmic scale, and any indicator that shall be drawn there must be "converted" to a logartmic scale as well. Look at MA.java or EMA.java for examples.

IMPORTANT: Please note that the IndicatorParameter should be static and only created once in the Indicator subclass. The reason for that is that otherwise it wouldn't be updated with correct parameters from the properties file or the "Options" menu. That means that it currently is impossible to have separate indicator parameters for separate charts.

How to use the classes the indicator receives

By far the most important class that is passed to the indicators is the LogDataSeries which contains all the daily (or weekly) data. The data is stored in a ArrayList of LogTradingData, one for each day (or week). The LogTradingData contains, among others, open, high low and closing prices and the date. LogDataSeries is a somewhat complicated class and the main reason for that is that it has the ability to set a "view" into the ArrayList. By setting a view other parts of the ArrayList is (almost) invisible. Normally a indicator would like to view the whole ArrayList so be sure to call the setCurrentPeriode() method. Without parameters this will set the view to the whole ArrayList. The hasNext() and getNext() method can be used to iterate the ArrayList in e.g. a while loop. Most indicators use the closing prices, the getClose() method in LogTradingData serves you well.

Modifying the Options menu

Introduction

The options menu was a kind of testbed for the indicator spesific menues. Each tab has its own class which is instantated by the PreferenceEditor class. The tab classes typically are named with there tab name with Menu added. Although there isn't a interface for the operations each tab class have to support, by convention several methodes are implemented by all tabs:

The UserPreferences instance is a singleton, so even if there are multiple instances of the PreferenceEditor, they all read and write to the same instanc of UserPreferences.

The Tab classes

Apart from the Indicator tab that get almost all components from the indicators themself, the tab classes defines all components that is displayed to the user except values for input field. The values are read from (and written to) the UserPreferences instance.

In addition to the public methodes mentioned above they all use the private methods (implemenatation is different from each class):

This makes adding new components to a tab fairly easy, but there is a couple of things to remember. First is that most tab classes uses a variable for the number of rows and columns. If components are added or removed they must be updated. The compoents must be defined, complete with toolTip and all in initComponents. If saving and restoring is applicable, please update save() and restore() and finally place the components in the array. Even more finally is to update the UserPreferences class with any new parameter that shall be stored in the properties file. Note that I'm considering to rewrite the UserPreferences to be more in style with the implementation used in the indicator classes. More about that later.

If a new tab is added, the PreferenceEditor has to be updated with calls to the new tab as well.

Final remark

As I have released this application as open source, I will of course listen to feedback from users others than myself. I am open for requests and/or help with coding. Also, as this started as an attempt to learn Java, I very much would like critique and suggestions on how I could improve the way I write Java. Please mail me at jstock (at) exponto.com