WebCab Technical Analysis
(J2EE Edition)

com.webcab.ejb.finance.trading.indicators
Interface Stochastics

All Superinterfaces:
EJBObject, Remote

public interface Stochastics
extends EJBObject

The Stochastics Oscillator compares the closing price with the price over a given period. Here we have implemented a fast %K Stochastic and a general %D Stochastic. The general of the %D Stochastic lies in the fact that the method by which the moving average is evaluated can be selected.

Interpretation and Application

Stochastic Oscillator's produce two time series, %K, and its moving average (MA) usually denoted by %D. These two lines are usual plotted on the same graph since the interaction is generally used in order to determine trading signals.

Below we describe three popular way in which the Stochastic indicator in interpreted in order to produce trading signals:

  1. Extreme Values - Buy when the Oscillator (either the Stochastic %K or its moving average %D) falls below a specific level (e.g., 20) and then rises above that level. Sell when the Oscillator rises above a specific level (e.g., 80) and then falls below that level. This approach is the preferred method of the Stochastics original creator George Lane.
  2. Crossing - Buy when the Stochastic %K, crosses above the MA %D and sell when the Stochastic %K falls below the MA of Stochastic %D. This will give more trading signals than the above method and is only suitable when the market in trending over the range that you are considering.
  3. Divergence - By searching for any divergences between the price dynamics and the Stochastic indicator %K. The Stochastic will often indicate when a trend trend is about the change direction (i.e. "its losing steam"). A good example is when the price is making a series of higher highs but the Stochastic is falling to make higher highs.


Method Summary
 int crossingSignal(double firstStochasticLast, double firstStochasticPrevious, double secondStochasticLast, double secondStochasticPrevious)
          Implements a general framework for producing trading signals based on the crossing of two Stochastics.
 double dStochastic(double[] stochastic, int method)
          Evaluate the (general) %D Stochastic.
 int extremeValueSignal(double extremeLow, double extremeHigh, double lastStochastic, double previousStochastic)
          Implements a general framework for producing extreme value trading signals in accordance with the follow.
 double kFastStochastic(double[] high, double[] low, double close)
          Evaluation of the Fast %K Stochastic.
 
Methods inherited from interface javax.ejb.EJBObject
getEJBHome, getHandle, getPrimaryKey, isIdentical, remove
 

Method Detail

kFastStochastic

public double kFastStochastic(double[] high,
                              double[] low,
                              double close)
                       throws RemoteException
Evaluation of the Fast %K Stochastic.

Indicator variables

The Stochastic %K depends on the following variable:

Within this method these parameters are set indirectly by the length of the array's which are passed to the method. That is, if the array's have length 5, then the fast Stochastic is evaluated over the last 5 trading period, referred to as the 5-day %K Stochastic.

Now the formulae for the Stochastic %K is:



100 x (Last Close - Lowest low)/(Highest high - Lowest low)

where the "lowest low" (respec. "highest high") is the highest (respec. lowest) close of the asset over the period under consideration. Since the "Last close", will lie between the highest high and lowest low this indicator will lie between 0 and 100.

Parameters:
high - an array of trading highs during the previous trading sessions. The length of this array corresponds to the number of periods over which the %K Stochastic is evaluated.
low - an array of trading lows during the previous trading sessions. The length of this array corresponds to the number of periods over which the %K Stochastic is evaluated.
close - the close price of the asset
RemoteException

dStochastic

public double dStochastic(double[] stochastic,
                          int method)
                   throws ReferencedServiceException,
                          RemoteException
Evaluate the (general) %D Stochastic. This is just the moving average of the (fast) %K Stochastic. When the simple moving average is used and the moving average is take over three days, the resulting indicator to referred to as the (slow) %K Stochastic.

As one would expect the Moving Average %D of the %K Stochastic depends on:

Remark When the simple moving average is used and it is evaluated over 3-days, then the %D Stochastic reduces to what is known as the slow %K Stochastic.

Parameters:
stochastic - the value of the stochastic over the period considered
method - determines the methods used for the evaluation of the moving average in accordance with the following key:
  1. 1 = Simple moving average
  2. 2 = Geometric moving average
  3. 3 = Linearly weighted moving average
  4. 4 = Exponentially Weighted Moving average within smoothing fact set to be 0.5.

For further details concerning the definition of these moving averages please see the accompanying PDF documentation or the API documentation for MovingAverage.

ReferencedServiceException
RemoteException

extremeValueSignal

public int extremeValueSignal(double extremeLow,
                              double extremeHigh,
                              double lastStochastic,
                              double previousStochastic)
                       throws RemoteException
Implements a general framework for producing extreme value trading signals in accordance with the follow. Note, that the general ides of this approach is to seek points which are oversold or over brought levels which are turning.

Methodology

Buy when the Oscillator (either the Stochastic %K or its moving average %D) falls below a specific level (e.g., 20) and then rises above that level. Sell when the Oscillator rises above a specific level (e.g., 80) and then falls below that level. This approach is the preferred method of the Stochastics original creator George Lane.

Parameters:
extremeLow - this is the level at which the Stochastic is believed to indicate an oversold level. The Stochastic always lies between 0 and 100, and a suggested extreme low value to take is 20.
extremeHigh - this is the level at which the Stochastic is believed to indicate an over brought level. The Stochastic always lies between 0 and 100, and a suggested extreme high value is 80.
lastStochastic - - This is the last value of the Stochastic (either %K or %D).
previousStochastic - - This is the previous value of the Stochastic (either %K or %D)
Returns:
-1, 0, 1 - this method returns either -1, 0, 1 to indicate that either a sell, no action or buy signal was generated.
RemoteException

crossingSignal

public int crossingSignal(double firstStochasticLast,
                          double firstStochasticPrevious,
                          double secondStochasticLast,
                          double secondStochasticPrevious)
                   throws RemoteException
Implements a general framework for producing trading signals based on the crossing of two Stochastics.

Methodology

Buy when the Stochastic %K, crosses above the MA %D and sell when the Stochastic %K falls below the MA of Stochastic %D. Since this approach is prone to being whip-sawed we use two (general) Stochastics so that a MA of the %K Stochastic of the first Stochastic and an even more smoothed second Stochastic. In this case a sell signal is generated if the first (more sensitive) Stochastic cross below the second (smoothed) Stochastic, and a buy signal is generated if the first Stochastic crosses above the second Stochastic.

Parameters:
firstStochasticLast - - The last value of the first Stochastic. Where the first Stochastic is either the (fast) %K Stochastic or a smoothed moving average of this indicator.
firstStochasticPrevious - - The previous value of the first Stochastic.
secondStochasticLast - - The last value of the second Stochastic.
secondStochasticPrevious - - The previous value of the second Stochastic is a moving average of the first stochastic.
Returns:
-1, 0, 1 - this method returns either -1, 0, 1 to indicate that either a sell, no action or buy signal was generated.
RemoteException

WebCab Technical Analysis
(J2EE Edition)