Directional Movement

All functions · nseries package

DMIMinus

func (s Series) DMIMinus(h, l, c Series, n int) Series

DMIMinus computes the negative Directional Movement Indicator over n bars. It measures the strength of downward price movement, consistent with the TradeStation DirMovement implementation.

If a high, low or close is NaN or infinite, the result is NaN from that bar onwards, except on the first bar, whose result is always 0; earlier bars are unaffected. A close counts on its own bar, although the calculation first reads it on the next one, and any later bad bars change nothing. This is the library’s policy for recursive methods: a non-finite value poisons the running averages permanently, so the result does not recover. It is NaN rather than 0 because 0 would read as “no downward movement” and pass for a real reading instead of showing up as missing data. Ordered comparisons such as > and < are false for NaN, and != is true, so test the result with math.IsNaN before comparing it with a threshold. The rule is keyed on the input values, not on the arithmetic: finite inputs whose arithmetic overflows, such as magnitudes near 1e308, are outside it and keep whatever result that arithmetic gives, which can include infinities or NaN.

The result is a new series of the same length as the inputs. If n is less than 1, or the series are empty or differ in length, it is an empty, non-nil series and the values are not inspected. Any n of 1 or more is accepted, even one longer than the series. The receiver is not used and may be nil.

The Wilder averages start from zero, so the first values after bar 0 are partial; the numerator and the denominator share the same weights, so the ratio is largely unaffected.

DMIPlus

func (s Series) DMIPlus(h, l, c Series, n int) Series

DMIPlus computes the positive Directional Movement Indicator over n bars. It measures the strength of upward price movement, consistent with the TradeStation DirMovement implementation.

If a high, low or close is NaN or infinite, the result is NaN from that bar onwards, except on the first bar, whose result is always 0; earlier bars are unaffected. A close counts on its own bar, although the calculation first reads it on the next one, and any later bad bars change nothing. This is the library’s policy for recursive methods: a non-finite value poisons the running averages permanently, so the result does not recover. It is NaN rather than 0 because 0 would read as “no upward movement” and pass for a real reading instead of showing up as missing data. Ordered comparisons such as > and < are false for NaN, and != is true, so test the result with math.IsNaN before comparing it with a threshold. The rule is keyed on the input values, not on the arithmetic: finite inputs whose arithmetic overflows, such as magnitudes near 1e308, are outside it and keep whatever result that arithmetic gives, which can include infinities or NaN.

The result is a new series of the same length as the inputs. If n is less than 1, or the series are empty or differ in length, it is an empty, non-nil series and the values are not inspected. Any n of 1 or more is accepted, even one longer than the series. The receiver is not used and may be nil.

The Wilder averages start from zero, so the first values after bar 0 are partial; the numerator and the denominator share the same weights, so the ratio is largely unaffected.