com.exponto.jstock.indicators
Class Indicator

java.lang.Object
  extended bycom.exponto.jstock.indicators.Indicator
All Implemented Interfaces:
IndicatorInterface
Direct Known Subclasses:
CandleStick, EMA, MA, Macd, Rsi

public abstract class Indicator
extends java.lang.Object
implements IndicatorInterface

The base class for all indicators. A few methods of the indicator interface are implemented here, the rest are found in the subclasses that implements the actual indicators. A indicator must at least implement the interfaces IndicatorInterface and IndicatorParametersInterface. The first for providing basic indicator "services" and the last in order to make the user able to modify the indicator parameters.

Author:
kaare

Field Summary
protected  java.awt.Color sm_indicatorColor
           
protected  java.lang.String sm_indicatorName
           
protected  boolean sm_isDisplayed
           
 
Constructor Summary
Indicator()
           
 
Method Summary
protected  int displayNumberToArrayIndex(int n, GraphicsParameters graphicsParameters, java.util.ArrayList indicatorSeries)
          Avoid using this as it is not correct in all cases - will be removed Finds the place in the indicatorSeries for a particular posistion on the display
abstract  boolean drawWithCandleSticks()
          Information for the class that allocates screenspace wheter a particular indicator requires a separate screen space or if it shall be painted with the candlesticks.
 java.awt.Color getColor()
           
abstract  java.lang.String getDailyPrintOut(int n)
          Makes a String with name, parameters and value (e.g.
 boolean getDisplayed()
          Information to other classes wheter this instance of an indicator shall be displayed on screen or not.
 java.lang.String getIndicatorName()
           
abstract  IndicatorParameters getIndicatorParameters()
          This returns the IndicatorParameter used together with a specific indicator.
abstract  boolean hasChanged()
          Check if the calling class can use data obtained from a previous call to paintIndicator or not.
abstract  void initiateIndicator(LogDataSeries lDS)
          Initiates an indicator with the provided LogDataSeries combined with indicator specific parameters either provied from a properties file or the user.
abstract  void initiateIndicator(LogDataSeries lDS, java.lang.String indParam)
          As above but with Indicatorparameters provided in a string format.
 boolean isMainIndicator()
          One of the indicators is a main indicator and is given more screen space than the rest.
abstract  void paintIndicator(java.awt.Graphics2D g2d, GraphicsParameters gP)
          Sends the Indicator a Graphics2D and asks it to paint itself on that Graphics.
abstract  java.lang.String[] printAll(int number)
          Generates an Array of strings that is suitable for printing to file or debugging purposes with all data within the range.
 void setColor(java.awt.Color color)
           
 void setDisplayed(boolean b)
          Gives other classes an opportunity to change the display status of this indicator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.exponto.jstock.indicators.IndicatorInterface
supportIndicatorValuesInterface
 

Field Detail

sm_indicatorName

protected java.lang.String sm_indicatorName

sm_indicatorColor

protected java.awt.Color sm_indicatorColor

sm_isDisplayed

protected boolean sm_isDisplayed
Constructor Detail

Indicator

public Indicator()
Method Detail

getIndicatorParameters

public abstract IndicatorParameters getIndicatorParameters()
Description copied from interface: IndicatorInterface
This returns the IndicatorParameter used together with a specific indicator. If none is specifically defined in the class, the default static indicatorparameter is returned.

Specified by:
getIndicatorParameters in interface IndicatorInterface
Returns:
the IndicatorParameter associated with the specific indicator.

initiateIndicator

public abstract void initiateIndicator(LogDataSeries lDS)
Description copied from interface: IndicatorInterface
Initiates an indicator with the provided LogDataSeries combined with indicator specific parameters either provied from a properties file or the user.

Specified by:
initiateIndicator in interface IndicatorInterface
Parameters:
lDS - The LogDataSeries containg values to computes the indicator

initiateIndicator

public abstract void initiateIndicator(LogDataSeries lDS,
                                       java.lang.String indParam)
Description copied from interface: IndicatorInterface
As above but with Indicatorparameters provided in a string format. The string will be passed on to a new instance of indicatorParameters for decoding.

Specified by:
initiateIndicator in interface IndicatorInterface
Parameters:
lDS -

getDisplayed

public boolean getDisplayed()
Description copied from interface: IndicatorInterface
Information to other classes wheter this instance of an indicator shall be displayed on screen or not. Indicators, or more correctly indicators parameters, that are stored in a database is not deleted in order to keep references to user drawn lines that may exist in the database. This methode gives information if the indicator is "active" (and shall be displayed).

Specified by:
getDisplayed in interface IndicatorInterface
Returns:
true if the indicator shall be displayed, fasle otherwise

setDisplayed

public void setDisplayed(boolean b)
Description copied from interface: IndicatorInterface
Gives other classes an opportunity to change the display status of this indicator. Typically used by the ticker specific indicator ui and classes loading indicators from the database.

Specified by:
setDisplayed in interface IndicatorInterface
Parameters:
b - - true if the indicator shall be displayed, false ohterwise.

isMainIndicator

public boolean isMainIndicator()
Description copied from interface: IndicatorInterface
One of the indicators is a main indicator and is given more screen space than the rest. At the time of writing only on main indicator is supported (candlesticks). If more than one indicator a mechanism for selecting one of them must be written.

Specified by:
isMainIndicator in interface IndicatorInterface
Returns:
true if the indicator is a main indicator, false otherwise

drawWithCandleSticks

public abstract boolean drawWithCandleSticks()
Description copied from interface: IndicatorInterface
Information for the class that allocates screenspace wheter a particular indicator requires a separate screen space or if it shall be painted with the candlesticks.

Specified by:
drawWithCandleSticks in interface IndicatorInterface
Returns:
true if this indicator shall be drawn in the same panel as the candlesticks, false if it shall be drawn in a separate panel

hasChanged

public abstract boolean hasChanged()
Description copied from interface: IndicatorInterface
Check if the calling class can use data obtained from a previous call to paintIndicator or not. The intention is that the calling class may store the graphics in an image in order to speed up the drawing time (at the cost of memory)

Specified by:
hasChanged in interface IndicatorInterface
Returns:
true if the parameters for this indicator has changed, false otherwise

paintIndicator

public abstract void paintIndicator(java.awt.Graphics2D g2d,
                                    GraphicsParameters gP)
Description copied from interface: IndicatorInterface
Sends the Indicator a Graphics2D and asks it to paint itself on that Graphics.

Specified by:
paintIndicator in interface IndicatorInterface
Parameters:
g2d - the Graphics to paint on

getDailyPrintOut

public abstract java.lang.String getDailyPrintOut(int n)
Description copied from interface: IndicatorInterface
Makes a String with name, parameters and value (e.g. "RSI(14) = 74") that can be used to print information about a particular day on screen. The Indicators them self has only indirect knowledge about dates other than start and stop date for the indicator, so the indicator number displayed on screen are used. 0 is the leftmost visible indicator.

Specified by:
getDailyPrintOut in interface IndicatorInterface
Parameters:
n - the number of day (0 is the first visible day on screen
Returns:
a String with Indicator name and value(s) that may be displayed on screen

printAll

public abstract java.lang.String[] printAll(int number)
Description copied from interface: IndicatorInterface
Generates an Array of strings that is suitable for printing to file or debugging purposes with all data within the range. There shall be one String per timeperiode (e.g. one per day for daily charts). A header String may also be generated. Note that the start and stop values shall be based on the original LogDataSeries and not the indicator series. If the indicatorSeries has no valid data for parts of the series "not valid" may be printed.

Specified by:
printAll in interface IndicatorInterface
Parameters:
number - of values to print, starting from the latest
Returns:
a String array with all values within the range

getColor

public java.awt.Color getColor()

setColor

public void setColor(java.awt.Color color)
Parameters:
color - - Sets the indicators color. Note that some indicators uses more than one color, this is the "main" color.

getIndicatorName

public java.lang.String getIndicatorName()
Specified by:
getIndicatorName in interface IndicatorInterface
Returns:
the name of the indicator

displayNumberToArrayIndex

protected int displayNumberToArrayIndex(int n,
                                        GraphicsParameters graphicsParameters,
                                        java.util.ArrayList indicatorSeries)
Avoid using this as it is not correct in all cases - will be removed Finds the place in the indicatorSeries for a particular posistion on the display

Parameters:
n - the posistion on display
Returns:
the position in the indicatorSeries


Copyright © 2004 Kaare Ranum