|
WebCab Technical Analysis v1.1 (J2SE Edition) |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--webcab.lib.finance.trading.indicators.DirectionalMovementIndicator
Implements the Directional Movement Indicator (MDI) and Average Directional Indicator (ADX) which was first developed by Wellas Wilder in order to classify price moves and trends. These ideas where first made public within Wilder's first book "New Concepts in Technical Trading Systems" (Dec 1978).
The techniques described here where originally developed in the process of developing a trading system and can still be used in this way. Today these methods are most commonly used to evaluate the strength of a price move or trend. Care should be taken with the direct application of this approach since it was first developed and applied to markets with exhibited lower volatility than todays markets.
The central idea of this approach is to compare the range of price of two subsequent periods and from this information infer the overall direction of the market. In order to ensure the stability of the indicators a moving average is often used in conjunction with the basic indicators. For further details please see the PDF documentation.
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:
ABCIndicator - Evaluation of the indicator over the whole period of length N.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.
| Constructor Summary | |
DirectionalMovementIndicator()
Creates a new instance. |
|
| Method Summary | |
double |
averageDailyTrueRange(double[] trueRange)
Evaluates the x-day Average Daily True Range (ADTR) of an asset. |
int |
classifyMovements(double todaysHigh,
double todaysLow,
double yesterdaysHigh,
double yesterdaysLow)
Determines whether todays price action represents an (up or down) trend, (up or down) gap, or an (inner or outer) range. |
double |
directionalMotion(double plusDirectionalMovement,
double minusDirectionalMovement)
Calculates the Directional Indicator which forms the main part of the Directional Movement System developed by Wellas Wilder over a number of periods. |
double |
directionalMotion(double todaysHigh,
double todaysLow,
double yesterdaysHigh,
double yesterdaysLow,
double yesterdaysClose)
Evaluates the Directional Movement Indicator (DMI) which forms the main part of the Directional Movement System developed by Wellas Wilder using only price data. |
double[] |
directionalMotionPeriod(double[] plusDirectionalMovement,
double[] minusDirectionalMovement)
Calculates the Directional Indicator which forms the main part of the Directional Movement System developed by Wellas Wilder. |
int |
dmiSignal(double[] pdi,
double[] mdi,
int method)
Evaluates what is know as the Directional Motion Indicator (MDI) Trading Signal. |
int[] |
dmiSignalPeriod(double[] pdi,
double[] mdi,
int method,
int lengthOfMA)
Evaluates what is know as the Directional Motion Indicator (MDI) Trading Signal. |
double |
minusDirectionalMovement(double trueRange,
double minusDirectionalMovement)
Evaluates the Minus Directional Movement Indicator (DMI) of the Current Bar. |
double |
minusDirectionalMovement(double todaysHigh,
double todaysLow,
double yesterdaysHigh,
double yesterdaysLow)
Evaluates the Minus Directional Movement (MDM). |
double |
minusDirectionalMovement(double todaysHigh,
double todaysLow,
double yesterdaysHigh,
double yesterdaysLow,
double yesterdaysClose)
Evaluates the Minus Directional Movement Indicator (MDMI) of the Current Bar using price data only. |
double[] |
minusDirectionalMovementPeriod(double[] high,
double[] low,
double[] close)
Evaluates the Minus Directional Movement Indicator (MDMI) over a number of periods using price data only. |
double |
plusDirectionalMovement(double trueRange,
double positiveDirectionalMovement)
Calculates the Plus Directional Movement Indicator (DMI) of the Current Bar. |
double |
plusDirectionalMovement(double todaysHigh,
double todaysLow,
double yesterdaysHigh,
double yesterdaysLow,
double yesterdaysClose)
Evaluates the Plus Directional Movement Indicator (PDMI) of the Current Bar using price data only. |
double[] |
plusDirectionalMovementPeriod(double[] high,
double[] low,
double[] close)
Evaluates the Plus Directional Movement Indicator (PDMI) over a number of periods using price data only. |
double |
positiveDirectionalMovement(double todaysHigh,
double todaysLow,
double yesterdaysHigh,
double yesterdaysLow)
Evaluates the Positive Directional Movement (PDM). |
double |
trueRange(double high,
double low,
double previousClose)
Finds the True Range (TR) for a given traded asset over a given period. |
double[] |
trueRangePeriod(double[] highs,
double[] lows,
double[] closing)
True Range (TR) of a traded asset over a number of periods. |
double[] |
twoDoubles2Array(double first,
double second)
Utility method used within client applications in order to write two doubles within an array of length 2. |
double |
wilderAverageDirectionalMotion(double todaysHigh,
double todaysLow,
double yesterdaysHigh,
double yesterdaysLow,
double yesterdaysClose,
double nDaysHigh,
double nDaysLow,
double yesterdaysNDaysHigh,
double yesterdaysNDaysLow,
double yesterdaysNDaysClose)
Evaluates the Average Directional Movement Index Rating (ADXR), which is a component of the Directional Movement System developed by Welles Wilder. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public DirectionalMovementIndicator()
| Method Detail |
public int classifyMovements(double todaysHigh,
double todaysLow,
double yesterdaysHigh,
double yesterdaysLow)
Here we detail explicitly what we mean by the terms trend, gap and range. We compare the range of the todays price with yesterdays range of prices and classify the price dynamics according to the following categories:
(todaysHigh > yesterdaysHigh) and (todaysLow > yesterdaysLow)(todaysHigh < yesterdaysHigh) and (todaysLow < yesterdaysLow)(todaysHigh > yesterdaysHigh) and (todaysLow > yesterdaysHigh)(todaysHigh < yesterdaysLow) and (todaysLow < yesterdaysLow)(todaysHigh ≥ yesterdaysHigh) and (todaysLow ≤ yesterdaysLow)(todaysHigh ≤ yesterdaysHigh) and (todaysLow ≥ yesterdaysLow)where:
Remarks:
todaysHigh - the highest traded value which the asset under consideration takes during todays market actiontodaysLow - the lowest traded value which the asset under consideration takes during todays market actionyesterdaysHigh - the highest traded value which the asset under consideration takes during yesterdays market actionyesterdaysLow - the lowest traded value which the asset under consideration takes during yesterdays market action
= 1= 2= 3= 4= 5= 6IllegalArgumentException - thrown if any of the parameters todaysHigh,
todaysLow, yesterdaysHigh or yesterdaysLow is a strictly negative number.
public double positiveDirectionalMovement(double todaysHigh,
double todaysLow,
double yesterdaysHigh,
double yesterdaysLow)
todaysHigh - the highest traded value which the asset under consideration takes during todays market actiontodaysLow - the lowest traded value which the asset under consideration takes during todays market actionyesterdaysHigh - the highest traded value which the asset under consideration takes during yesterdays market actionyesterdaysLow - the lowest traded value which the asset under consideration takes during yesterdays market action
IllegalArgumentException - thrown if any of the parameters todaysHigh, todaysLow,
yesterdaysHigh or yesterdaysLow is a strictly negative number.
public double minusDirectionalMovement(double todaysHigh,
double todaysLow,
double yesterdaysHigh,
double yesterdaysLow)
todaysHigh - the highest traded value which the asset under consideration takes during todays market actiontodaysLow - the lowest traded value which the asset under consideration takes during todays market actionyesterdaysHigh - the highest traded value which the asset under consideration takes during yesterdays market actionyesterdaysLow - the lowest traded value which the asset under consideration takes during yesterdays market action
IllegalArgumentException - thrown if any of the parameters todaysHigh, todaysLow,
yesterdaysHigh or yesterdaysLow is a strictly negative number.
public double trueRange(double high,
double low,
double previousClose)
high - the highest traded value of the last trading period.low - the lowest traded value of the last trading period.previousClose - the closing price of the asset on the preceding trading period.
IllegalArgumentException - thrown if any of the parameters high, low
or previousClose is a strictly negative number.averageDailyTrueRange - Evaluates the x-day Average of the Daily True Range (ADTR).,
trueRangePeriod - Evaluate the True Range (TR) over a number of trading periods.
public double[] trueRangePeriod(double[] highs,
double[] lows,
double[] closing)
trueRange over a number of consecutive periods.
highs - a double array where a first term contains the value of the highest traded price during the last trading period considered, the second terms contains the highest traded price in the previous trading periods and on so.lows - a double array where a first term contains the value of the lowest traded price during the last trading period considered, the second terms contains the lowest traded price in the previous trading periods and on so.closing - a double array where a first term contains the value of the closing price during the last trading period considered, the second terms contains the closing price in the previous trading periods and on so.
IllegalArgumentException - thrown if the length of the array parameters high,
low or closing, is not the same or if any elements of any one
of these array's has a negative element.trueRange - Evaluate the True Range over a single period.public double averageDailyTrueRange(double[] trueRange)
x-day Average Daily True Range (ADTR) of an asset. This measure
is often used as a measure of volatility. The ADTR is the simple moving average of daily true
which can be evaluated using trueRange.
trueRange - an array of (positive) doubles of length x, where the first element is the true range over the last trading session, the second value of the true range range over the previous trading session and so on.
IllegalArgumentException - thrown if any element of the array is strictly negative.
The elements of the trueRange array cannot be strictly negative since they represent the
(positive) true range's (TRs) of an asset over a period.trueRange - To evaluate the trueRange parameter.
public double plusDirectionalMovement(double trueRange,
double positiveDirectionalMovement)
trueRange - the true range of the Current Bar (i.e. todays) which can be evaluated using trueRange.positiveDirectionalMovement - the positive directional movement of the asset over the past day which can be evaluated using positiveDirectionalMovement.
IllegalArgumentException - thrown if the trueRange is not positive.trueRange - To evaluate the trueRange parameter.,
positiveDirectionalMovement - To evaluate the positive directional movement parameter.
public double minusDirectionalMovement(double trueRange,
double minusDirectionalMovement)
trueRange - the true range of the Current Bar (i.e. todays)minusDirectionalMovement - the minus directional movement of the asset over the past day
IllegalArgumentException - thrown if the trueRange is not positive.trueRange,
minusDirectionalMovement
public double plusDirectionalMovement(double todaysHigh,
double todaysLow,
double yesterdaysHigh,
double yesterdaysLow,
double yesterdaysClose)
todaysHigh - the highest traded value which the asset under consideration takes during todays market actiontodaysLow - the lowest traded value which the asset under consideration takes during todays market actionyesterdaysHigh - the highest traded value which the asset under consideration takes during yesterdays market actionyesterdaysLow - the lowest traded value which the asset under consideration takes during yesterdays market actionyesterdaysClose - the close price of the asset the preceding day
IllegalArgumentException - thrown if any of the parameters todaysHigh, todaysLow,
yesterdaysHigh, yesterdaysLow or yesterdaysClose is not a positive number.
public double[] plusDirectionalMovementPeriod(double[] high,
double[] low,
double[] close)
high - an array where the first term is the intraday high over the most recent period, the second term is the high over the previous period and so on.low - an array where the first term is the intraday low over the most recent period, the second term is the low over the previous period and so on.close - an array where the first term is the intraday close over the most recent period, the second term is the close over the previous period and so on.
IllegalArgumentException - throw when the three arrays high, low, close do not have the
same length, or when any element of these three arrays is a strictly negative number.plusDirectionalMovement - evaluates the PDMI of the Current Bar using
price data only
public double minusDirectionalMovement(double todaysHigh,
double todaysLow,
double yesterdaysHigh,
double yesterdaysLow,
double yesterdaysClose)
todaysHigh - the highest traded value which the asset under consideration takes during todays market actiontodaysLow - the lowest traded value which the asset under consideration takes during todays market actionyesterdaysHigh - the highest traded value which the asset under consideration takes during yesterdays market actionyesterdaysLow - the lowest traded value which the asset under consideration takes during yesterdays market actionyesterdaysClose - the close price of the asset the preceding day
IllegalArgumentException - thrown if any of the parameters todaysHigh, todaysLow,
yesterdaysHigh, yesterdaysLow or yesterdaysClose is not a positive number.
public double[] minusDirectionalMovementPeriod(double[] high,
double[] low,
double[] close)
high - an array where the first term is the intraday high over the most recent period, the second term is the high over the previous period and so on.low - an array where the first term is the intraday low over the most recent period, the second term is the low over the previous period and so on.close - an array where the first term is the intraday close over the most recent period, the second term is the close over the previous period and so on.
IllegalArgumentException - throw when the three arrays high, low, close do not have the
same length, or when any element of these three arrays is a strictly negative number.minusDirectionalMovement - evaluates the MDMI of the Current Bar using
price data only
public double directionalMotion(double todaysHigh,
double todaysLow,
double yesterdaysHigh,
double yesterdaysLow,
double yesterdaysClose)
The Directional Movement Indicator (DMI) can be summarized by the following formula:
Directional Movement Indicator = 100 * ( (PDM - MDM) / (PDM + MDM) ),
where PDM is the Plus Directional Movement (PDM) indicator over the last two
trading periods which can be evaluated using plusDirectionalMovement
and MDM is the Minus Directional Movement (MDM) indicator over the last two
trading periods which can be evaluated using minusDirectionalMovement.
The Directional movement indicator has a range of [0,100], where to higher the
value returned the stronger the trend is said to be. If a trend is reliable then
the directional lines (PDM and MDM) will diverge and the indicator will increase.
If on the other hand a trend starts to fail and price whip-saws (for example with
price is within a trading range) the difference between the direction lines will
decrease and the overall index will decrease.
todaysHigh - the highest traded value which the asset under consideration takes during todays market actiontodaysLow - the lowest traded value which the asset under consideration takes during todays market actionyesterdaysHigh - the highest traded value which the asset under consideration takes during yesterdays market actionyesterdaysLow - the lowest traded value which the asset under consideration takes during yesterdays market actionyesterdaysClose - the closing price of the asset the preceding day
IllegalArgumentException - thrown if any of the parameters todaysHigh, todaysLow,
yesterdaysHigh, yesterdaysLow or yesterdaysClose is not a positive number.plusDirectionalMovement,
minusDirectionalMovement
public double directionalMotion(double plusDirectionalMovement,
double minusDirectionalMovement)
plusDirectionalMovement and
minusDirectionalMovement indicators.
The Directional Movement Indicator can be summarized by the following formula:
Directional Movement Indicator = 100 * ( (PDM - MDM) / (PDM + MDM) ),
where PDM is the Plus Directional Movement (PDM) indicator over the last two trading
periods which can be evaluated using plusDirectionalMovement and
MDM is the Minus Directional Movement (MDM) indicator over the last two trading periods
which can be evaluated using minusDirectionalMovement.
The directional indicator has a range of [0,100], where to higher the value
returned the stronger the trend is said to be. If a trend is reliable then the smoothed directional
lines (PDM and MDM) will diverge and the indicator will increase. If on the other hand a trend starts
to fail and price whip-saws (for example with price is within a trading range) the difference
between the smoothed direction lines will decrease and the overall index will decrease.
plusDirectionalMovement - the value of the Plus Directional Movement indicator corresponding to the last two trading periods. See plusDirectionalMovement for more details.minusDirectionalMovement - the value of the Minus Directional Movement indicator corresponding to the last two trading periods. See minusDirectionalMovement for more details.
plusDirectionalMovement - An array representinf the Plus Directional Movement indicators parameter.,
minusDirectionalMovement - An array representing the Minus Directional Movement indicators parameter.
public double[] directionalMotionPeriod(double[] plusDirectionalMovement,
double[] minusDirectionalMovement)
plusDirectionalMovement and
minusDirectionalMovement indicators.
The Directional Movement Indicator can be summarized by the following formula:
Directional Movement Indicator = 100 * ( (PDM - MDM) / (PDM + MDM) ),
where PDM is the Plus Directional Movement (PDM) indicator over the last two trading
periods which can be evaluated using plusDirectionalMovement and
MDM is the Minus Directional Movement (MDM) indicator over the last two trading periods
which can be evaluated using minusDirectionalMovement.
The directional indicator has a range of [0,100], where to higher the value
returned the stronger the trend is said to be. If a trend is reliable then the smoothed directional
lines (PDM and MDM) will diverge and the indicator will increase. If on the other hand a trend starts
to fail and price whip-saws (for example with price is within a trading range) the difference
between the smoothed direction lines will decrease and the overall index will decrease.
plusDirectionalMovement - the value of the Plus Directional Movement indicator corresponding to the last two trading periods. See plusDirectionalMovement for more details.minusDirectionalMovement - the value of the Minus Directional Movement indicator corresponding to the last two trading periods. See minusDirectionalMovement for more details.
plusDirectionalMovement - In order to evaluate the Plus Directional Movement indicator parameter.,
minusDirectionalMovement - In order to evaluate the Minus Directional Movement indicator parameter.
public int dmiSignal(double[] pdi,
double[] mdi,
int method)
throws ReferencedServiceException
At its simplest level to DMI system states that when the PDI crosses above the MDI a buy signal is generated and when the MDI crosses above the PMI then a sell signal is generated. This however may generate an excessive number of signals and hence we offer the possibility to smooth out these indicators according to a moving average which will help to reduce to sensitivity of the trading system.
This trading approach will reveal a trend before it is detected by most market participants. Once the trend becomes more widely recognized other market participants will tend to buy the tend and hence re-enforcing the trend dynamics. Hence the DMI system offers a good risk/reward trend following system.
pdi - an array of the previous values of the positive directional indicator (PDI), where the length of the array is ONE MORE than the number of periods used within the moving average. Where pdi[0] is the latest value of the PDI indicator, pdi[1] is the previous value and so on. Note that the length of the array pdi and mdi, must be identical.mdi - an array of the previous values of the minus directional indicator (MDI), where the length of the array is one more than the number of periods used within the moving average. Where mdi[0] is the latest value of the MDI indicator, mdi[0] is the previous value and so on. Note that the length of the array pdi and mdi, must be identical.method - an integer which determines the method used in the evaluation of the moving average in accordance with the following key: -1, 0, or 1 respectively according to
whether a sell, no action or buy signal is generated.
ReferencedServiceException
public int[] dmiSignalPeriod(double[] pdi,
double[] mdi,
int method,
int lengthOfMA)
throws ReferencedServiceException
At its simplest level to DMI system states that when the PDI crosses above the MDI a buy signal is generated and when the MDI crosses above the PMI then a sell signal is generated. This however may generate an excessive number of signals and hence we offer the possibility to smooth out these indicators according to a moving average which will help to reduce to sensitivity of the trading system.
This trading approach will reveal a trend before it is detected by most market participants. Once the trend becomes more widely recognized other market participants will tend to buy the tend and hence re-enforcing the trend dynamics. Hence the DMI system offers a good risk/reward trend following system.
pdi - an array of the previous values of the positive directional indicator (PDI), where the length of the array must be grater than the number of periods used within the moving average. Where pdi[0] is the latest value of the PDI indicator, pdi[1] is the previous value and so on. Note that the length of the array pdi and mdi, must be identical.mdi - an array of the previous values of the minus directional indicator (MDI), where the length of the array is one more than the number of periods used within the moving average. Where mdi[0] is the latest value of the MDI indicator, mdi[0] is the previous value and so on. Note that the length of the array pdi and mdi, must be identical.method - an integer which determines the method used in the evaluation of the moving average in accordance with the following key: lengthOfMA - The number of periods over which the moving average is calculated.
-1, 0, or 1 respectively according to
whether a sell, no action or buy signal is generated.
ReferencedServiceException
public double wilderAverageDirectionalMotion(double todaysHigh,
double todaysLow,
double yesterdaysHigh,
double yesterdaysLow,
double yesterdaysClose,
double nDaysHigh,
double nDaysLow,
double yesterdaysNDaysHigh,
double yesterdaysNDaysLow,
double yesterdaysNDaysClose)
Originally Welles Wilder used the ADXR indicator to determine whether a trend was sufficiently strong enough in order to apply a trend following system. The rule was to only apply a trend following system when the ADXR was between 20 and 25. The ADXR can also be used within a system which uses the Directional Movement Indicator (for example Welles, Directional Movement System) which will result in trading signals being more infrequently generated.
The ADXR indicator is given by the following formula:
ADXR = ( directionalMotion(today) + directionalMotion(n-days ago) ) / 2
where directionalMotion(today) in the value of the Directional Motion Index (above) today
and directionalMotion(n-days ago) is the Directional Motion Index of the asset consideration
n-days ago.
todaysHigh - the highest traded value which the asset under consideration takes during todays market action.todaysLow - the lowest traded value which the asset under consideration takes during todays market action.yesterdaysHigh - the highest traded value which the asset under consideration takes during yesterdays market action.yesterdaysLow - the lowest traded value which the asset under consideration takes during yesterdays market action.yesterdaysClose - the closing price of the asset the preceding day.nDaysHigh - the highest traded value which the asset under consideration takes during the trading period n-days previously.nDaysLow - the lowest traded value which the asset under consideration takes during the trading period n-days previously.yesterdaysNDaysHigh - the highest traded value which the asset under consideration takes during the trading period (n+1)-days previously.yesterdaysNDaysLow - the lowest traded value which the asset under consideration takes during the trading period (n+1)-days previously.yesterdaysNDaysClose - the closing price of the asset on the trading period (n+1) days ago.
IllegalArgumentException - thrown if any of the methods double parameters is not
a positive number.
public double[] twoDoubles2Array(double first,
double second)
first - the first double within the array returned.second - the second double within the array returned.
first double
given as a parameter and the 2nd element is the second double given as a parameter.
|
WebCab Technical Analysis v1.1 (J2SE Edition) |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||