pythonta-lib

talib.PLUS_DM - shouldn't the return value be bounded by [0, 100]?


Why does this example return values out of the range [0, 100] for PLUS_DM, and why is it sensitive to scaling the values? I would assume with the ratio that changes of magnitude would cancel out.

import numpy as np
import talib

highs= np.array([39050.0, 39050.0, 39100.0, 39100.0, 39050.0, 39061.0, 39090.0, 39100.0, 39100.0, 39050.0, 39100.0, 39100.0, 39050.0, 39050.0, 39150.0, 39200.0, 39175.0, 39200.0, 39200.0, 39200.0, 39200.0,])
lows = np.array([39000.0, 39000.0, 39000.0, 39000.0, 39000.0, 39000.0, 39000.0, 39000.0, 39050.0, 39000.0, 39050.0, 39000.0, 39000.0, 39000.0, 39000.0, 39100.0, 39100.0, 39100.0, 39100.0, 39100.0, 39100.0,])

span =14
dmip = talib.PLUS_DM(highs, lows, span)


>>>dmip  
>>> 
array([         nan,          nan,          nan,          nan,
                nan,          nan,          nan,          nan,
                nan,          nan,          nan,          nan,
                nan, 150.        , 239.28571429, 272.19387755,
       252.75145773, 259.69778217, 241.14794059, 223.92308769,
       207.92858143])
       
       
highs = highs/10000
lows = lows/10000

dmip = talib.PLUS_DM(highs, lows, span)


>>>dmip  
>>> 
array([       nan,        nan,        nan,        nan,        nan
              nan,        nan,        nan,        nan,        nan,
              nan,        nan,        nan, 0.015     , 0.02392857,
       0.02721939, 0.02527515, 0.02596978, 0.02411479, 0.02239231,
       0.02079286])

Solution

  • PLUS_DM is expressed in the units of the original time series. By design, it will be larger if the underlying time series is larger.

    From CFI:

    If current high minus previous high is greater than the previous low minus current low,

    +DM = Current High – Previous High

    If +DM is negative, then +DM is taken as 0

    If you multiply both Current High and Previous High by 100, then the output will be multiplied by 100 too.