WebCab Technical Analysis
v1.1
(J2SE Edition)

webcab.lib.finance.trading.indicators
Class Stochastics

java.lang.Object
  |
  +--webcab.lib.finance.trading.indicators.Stochastics
All Implemented Interfaces:
Serializable

public class Stochastics
extends Object
implements Serializable

Oscillator's of Stochastic type such as fast %K Stochastic, %D Stochastic and associated trading signals such as Extremum Value, Crossing, Crossing Extreme. These stochastic indicators compare the most recent observed market variables (price, high, low etc) with the same market variables over a given historical period. Here we provide the (fast) %K Stochastic and its moving average known as the (slow) %D Stochastic.

Within this class we have implemented the fast %K Stochastic and a general implementation of the %D Stochastic. The generality 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 it is generally the interaction of these two indicators which is used in order to generate trading signals.

Below we describe three popular ways 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 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.

One Period and Multi Period Versions

For many of the indicators we provide essentially two versions of the same method. The first version evaluates the indicator over the entire period given and the second version evaluates the indicator over all the sub-periods of a given length. Moreover, the version which evaluates over all sub-periods of a given length will return the results as an array where the 1st term of the array will be the value associated with the most recent sub-period, and the previous element corresponding to the previous sub-period and so on.

The naming of these two versions will follow the convention that if the indicator which evaluates over the entire period and returns a single element is named ABCIndicator, then the corresponding indicator over all sub-periods (of a given length) which returns an array will be denoted by ABCIndicatorOverPeriod.

For example, if our source data has N elements then the two versions of a given indicator, where the number of periods used within the sub-periods is n would correspond to:

  1. ABCIndicator - Evaluation of the indicator over the whole period of length N.
  2. ABCIndicatorOverPeriod - Will return an array where the first term is the value of the indicator ABCIndicator on the most recent n periods, and the next term is the value of the indicator ABCIndicator on the previous n+1 periods minus the most recent period and so on. That is, for each iterative evaluation 'the window of evaluation' is shifted one place back.

See Also:
Serialized Form

Constructor Summary
Stochastics()
          Creates a new instance.
 
Method Summary
 int crossingExtremeSignal(double extremeLow, double extremeHigh, double firstStochasticLast, double firstStochasticPrevious, double secondStochasticLast, double secondStochasticPrevious)
          This trading system combines the features of the crossing and extremum value trading systems by requiring that a signal will only be generated if the fast %K Stochastic crosses the slow %D Stochastic either above or below the extremal values.
 int[] crossingExtremeSignalPeriod(double extremeLow, double extrememHigh, double[] high, double[] low, double[] close, int noOfPeriods, int method, int lengthOfMA)
          Crossing Extreme Trading system applied over a period.
 int[] crossingSignal(double[] high, double[] low, double[] close, int noOfPeriods, int method, int lengthOfMA)
          Implements a general framework for producing trading signals based on the crossing of two Stochastics.
 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.
 int[] crossingSignalPeriod(double[] firstStochastic, double[] secondStochastic)
          Implements a general framework for producing trading signals based on the crossing of two Stochastics.
 double[] dStochastic(double[] high, double[] low, double[] close, int noOfPeriods, int method, int lengthOfMA)
          Evaluate the (general) %D Stochastic over all periods using only price data.
 double dStochastic(double[] stochastic, int method)
          Evaluate the (general) %D Stochastic.
 double[] dStochastic(double[] stochastic, int method, int lengthOfMA)
          Evaluate the (general) %D Stochastic over all periods using known values of the stochastic.
 int[] extremeValueDSignalPeriod(double extremeLow, double extremeHigh, double[] high, double[] low, double[] close, int noOfPeriods, int method, int lengthOfMA)
          Implements a general framework for producing extreme value trading signals using Stochastic indicators.
 int[] extremeValueKSignalPeriod(double extremeLow, double extremeHigh, double[] high, double[] low, double[] close, int noOfPeriods)
          Implements a general framework for producing extreme value trading signals using Stochastic indicators.
 int extremeValueSignal(double extremeLow, double extremeHigh, double lastStochastic, double previousStochastic)
          Implements a general framework for producing extreme value trading signals using Stochastic indicators.
 double kFastStochastic(double[] high, double[] low, double close)
          Evaluation of the Fast %K Stochastic.
 double[] kFastStochasticPeriod(double[] highs, double[] lows, double[] close, int noOfPeriods)
          Evaluation of the Fast %K Stochastic over all possible sub-periods.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Stochastics

public Stochastics()
Creates a new instance.

Method Detail

kFastStochastic

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

Indicator Evaluation

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 Fast %K Stochastic is:

Fast %K Stochastic = 100 * (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 where the k-th term is the high during the k-th previous trading session. The length of this array corresponds to the number of periods over which the %K Stochastic is evaluated.
low - an array where the k-th term is the low during the k-th previous trading session. The length of this array corresponds to the number of periods over which the %K Stochastic is evaluated.
close - the previous closing price of the asset being considered.
Returns:
Double value of the Fast %K Stochastic.
See Also:
kFastStochasticPeriod

kFastStochasticPeriod

public double[] kFastStochasticPeriod(double[] highs,
                                      double[] lows,
                                      double[] close,
                                      int noOfPeriods)
Evaluation of the Fast %K Stochastic over all possible sub-periods.

Indicator Evaluation

The Stochastic %K depends on the following variable:

Now the formulae for a particular look back periods for the %K Stochastic is:

%K Stochastic = 100 * (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.

Here we evaluate the %K Stochastic over all possible periods. Which means that we first evaluate over the last noOfPeriods-periods using the above formula, we then evaluate from the previous periods until noOfPeriods + 1-periods previous, and so on.

Parameters:
highs - an array of trading highs where the 1st term is the high during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
lows - an array of trading lows where the 1st term is the low during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
close - an array of closing prices where the 1st term is the closing price during the last session and the 2nd term of the closing price during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
noOfPeriods - the number of periods used within the evaluation of the %K (fast) Stochastic.
Returns:
Returns an array where to the first term of the evaluation of the %K Stochastic over the most recent periods, the second term is the evaluation over the next most recent periods and so on.
See Also:
kFastStochastic

dStochastic

public double dStochastic(double[] stochastic,
                          int method)
                   throws ReferencedServiceException
Evaluate the (general) %D Stochastic. The %D Stochastic is just the moving average of the (fast) %K Stochastic which can be evaluated using kFastStochastic, where the length of the moving average used is the length of the stochastic parameter.

Note: If the simple moving average is used and the number of periods used is three then is such an instance we are said to be evaluating the (slow) %K Stochastic.

Further Details

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

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.

Returns:
A double value of the %D Stochastic.
ReferencedServiceException

dStochastic

public double[] dStochastic(double[] stochastic,
                            int method,
                            int lengthOfMA)
Evaluate the (general) %D Stochastic over all periods using known values of the stochastic. The %D Stochastic is just the moving average of the (fast) %K Stochastic which can be evaluated using kFastStochastic, where the length of the moving average is specified as a parameter.

Note: If the simple moving average is used and the number of periods used is three then is such an instance we are said to be evaluating the (slow) %K Stochastic.

Further Details

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

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.

lengthOfMA - the number of periods over which the moving average is considered
Returns:
An array where the first element represents the %D Stochastic over the most recent periods, the second terms represents the %D Stochastic over the previous most recent periods and so on.

dStochastic

public double[] dStochastic(double[] high,
                            double[] low,
                            double[] close,
                            int noOfPeriods,
                            int method,
                            int lengthOfMA)
Evaluate the (general) %D Stochastic over all periods using only price data. The %D Stochastic is just the moving average of the (fast) %K Stochastic which can be evaluated using kFastStochastic, where the length of the moving average is specified as a parameter.

Note: If the simple moving average is used and the number of periods used is three then is such an instance we are said to be evaluating the (slow) %K Stochastic.

Further Details

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

Parameters:
high - an array of trading highs where the 1st term is the high during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
low - an array of trading lows where the 1st term is the low during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
close - an array of closing prices where the 1st term is the closing price during the last session and the 2nd term of the closing price during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
noOfPeriods - the number of periods used within the evaluation of the %K (fast) Stochastic as provided by DStochastic.
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.

lengthOfMA - the number of periods over which the moving average is considered.
Returns:
An array where the first element represents the %D Stochastic over the most recent periods, the second terms represents the %D Stochastic over the previous most recent periods and so on.

extremeValueSignal

public int extremeValueSignal(double extremeLow,
                              double extremeHigh,
                              double lastStochastic,
                              double previousStochastic)
Implements a general framework for producing extreme value trading signals using Stochastic indicators. 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:
This method returns either -1, 0, 1, respectively; to indicate that either a sell, no action or buy signal was generated.

extremeValueKSignalPeriod

public int[] extremeValueKSignalPeriod(double extremeLow,
                                       double extremeHigh,
                                       double[] high,
                                       double[] low,
                                       double[] close,
                                       int noOfPeriods)
Implements a general framework for producing extreme value trading signals using Stochastic indicators. Note, that the general idea of this approach is to seek points which are oversold or over brought levels which are turning.

Methodology

Buy when the the Stochastic %K 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.
high - an array of trading highs where the 1st term is the high during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
low - an array of trading lows where the 1st term is the low during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
close - an array of closing prices where the 1st term is the closing price during the last session and the 2nd term of the closing price during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
noOfPeriods - the number of periods used within the evaluation of the %K (fast) Stochastic as provided by (double[], double[], double[], int) kFastStochasticPeriod.
Returns:
Returns an array consisting of -1, 0, 1, respectively; to indicate that either a sell, no action or buy signal was generated for each of the periods considered. Where the first term is the trading signal for the earliest period and the second term is the trading signal for the precious period and so on.
See Also:
extremeValueSignal - his indicator is a special case of extremeValueKSignalPeriod and calculates the extremeValueSignal indicator for a single period.

extremeValueDSignalPeriod

public int[] extremeValueDSignalPeriod(double extremeLow,
                                       double extremeHigh,
                                       double[] high,
                                       double[] low,
                                       double[] close,
                                       int noOfPeriods,
                                       int method,
                                       int lengthOfMA)
Implements a general framework for producing extreme value trading signals using Stochastic indicators. 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 the Stochastic %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.
high - an array of trading highs where the 1st term is the high during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
low - an array of trading lows where the 1st term is the low during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
close - an array of closing prices where the 1st term is the closing price during the last session and the 2nd term of the closing price during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
noOfPeriods - the number of periods used within the evaluation of the %D Stochastic as provided by (double[], int, int) DStochastic.
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.

lengthOfMA - the number of periods over which the moving average is evaluated.
Returns:
Returns an array consisting of -1, 0, 1, respectively; to indicate that either a sell, no action or buy signal was generated for each of the periods considered. Where the first term is the trading signal for the earliest period and the second term is the trading signal for the precious period and so on.
See Also:
extremeValueSignal - this indicator is a special case of extremeValueKSignalPeriod and calculates the extremeValueSignal indicator for a single period.

crossingSignal

public 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.

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:
Returns either -1, 0, 1, respectively; to indicate that either a sell, no action or buy signal respectively was generated.

crossingSignalPeriod

public int[] crossingSignalPeriod(double[] firstStochastic,
                                  double[] secondStochastic)
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:
firstStochastic - a double array of either the (fast) %K Stochastic or a smoothed moving average of the %K Stochastic. Where the 1st term of the array is the %K Stochastic for the most recent periods, and the 2nd term is the %K Stochastic for the next most recent periods and so on.
secondStochastic - a double array of the %D Stochastic where the 1st term of the array is the %D Stochastic for the most recent periods, and the 2nd term is the %D Stochastic for the next most recent periods and so on.
Returns:
Returns an array consisting of -1, 0, 1, respectively; to indicate that either a sell, no action or buy signal respectively was generated for each of the periods considered. Where the first term is the trading signal for the earliest period and the second term is the trading signal for the precious period and so on.
See Also:
crossingSignal - this indicator is a special case of crossingSignalPeriod and calculates the crossingSignal for a single period.

crossingSignal

public int[] crossingSignal(double[] high,
                            double[] low,
                            double[] close,
                            int noOfPeriods,
                            int method,
                            int lengthOfMA)
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:
high - an array of trading highs where the 1st term is the high during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
low - an array of trading lows where the 1st term is the low during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
close - an array of closing prices where the 1st term is the closing price during the last session and the 2nd term of the closing price during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
noOfPeriods - the number of periods used within the evaluation of the %D Stochastic as provided by (double[], int, int) DStochastic.
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.

lengthOfMA - the number of periods over which the moving average is considered
Returns:
An array consisting of -1, 0, 1, respectively; to indicate that either a sell, no action or buy signal was generated for each of the periods considered. Where the first term is the trading signal for the earliest period and the second term is the trading signal for the precious period and so on.
See Also:
crossingSignal - this indicator is a special case of crossingSignalPeriod, calculates the crossingSignal for a single period.

crossingExtremeSignal

public int crossingExtremeSignal(double extremeLow,
                                 double extremeHigh,
                                 double firstStochasticLast,
                                 double firstStochasticPrevious,
                                 double secondStochasticLast,
                                 double secondStochasticPrevious)
This trading system combines the features of the crossing and extremum value trading systems by requiring that a signal will only be generated if the fast %K Stochastic crosses the slow %D Stochastic either above or below the extremal values.

Trading System Rules

This system generates buy and sell signals respectively when one of the following is triggered:

  1. Buy Signal: When the fast %K Stochastic crosses above the slow %D Stochastic and this crossing takes place at a value lower than the extremumLow, then a buy signal is generated.
  2. Sell Signal: When the fast %K Stochastic crosses above the slow %D Stochastic and this crossing takes place at a value higher than the extremumHigh, then a sell signal in generated.

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.
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:
Returns either -1, 0, 1, respectively; to indicate that either a sell, no action or buy signal was generated.
See Also:
crossingExtremeSignalPeriod - this indicator is a general case of crossingExtremeSignal and calculates the crossingSignal for more periods.

crossingExtremeSignalPeriod

public int[] crossingExtremeSignalPeriod(double extremeLow,
                                         double extrememHigh,
                                         double[] high,
                                         double[] low,
                                         double[] close,
                                         int noOfPeriods,
                                         int method,
                                         int lengthOfMA)
Crossing Extreme Trading system applied over a period. The Trading system combines the features of the crossing and extremum value trading systems by requiring that a signal will only be generated if the fast %K Stochastic crosses the slow %D Stochastic either above or below the extremal values.

Trading System Rules

This system generates buy and sell signals respectively when one of the following is triggered:

  1. Buy Signal: When the fast %K Stochastic crosses above the slow %D Stochastic and this crossing takes place at a value lower than the extremumLow, then a buy signal is generated.
  2. Sell Signal: When the fast %K Stochastic crosses above the slow %D Stochastic and this crossing takes place at a value higher than the extremumHigh, then a sell signal in generated.

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.
high - an array of trading highs where the 1st term is the high during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
low - an array of trading lows where the 1st term is the low during the last trading session, the 2nd element is the trading high during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
close - an array of closing prices where the 1st term is the closing price during the last session and the 2nd term of the closing price during the previous session and so on. The length of this array should be greater than the number of periods over which the %K Stochastic is evaluated.
noOfPeriods - the number of periods used within the evaluation of the %D Stochastic as provided by (double[], int, int) DStochastic.
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.

lengthOfMA - the number of periods over which the moving average is considered.
Returns:
An array consisting of -1, 0, 1, respectively; to indicate that either a sell, no action or buy signal was generated for each of the periods considered. Where the first term is the trading signal for the earliest period and the second term is the trading signal for the precious period and so on.
See Also:
crossingExtremeSignal - this indicator is a special case of crossingExtremeSignalPeriod and calculates the crossingSignal for a single period.

WebCab Technical Analysis
v1.1
(J2SE Edition)