It seems the default lengths for the indicators cannot be changed without throwing errors like:
/usr/local/lib/python2.7/dist-packages/numpy/lib/function_base.pyc in average(a, axis, weights, returned)
529 if wgt.shape[0] != a.shape[axis]:
530 raise ValueError(
--> 531 "Length of weights not compatible with specified axis.")
532
533 # setup wgt to broadcast along axis
ValueError: Length of weights not compatible with specified axis.
This seems to do the trick for allowing any length though:
class ADX(CustomFactor):
# Average Directional Movement Index
# Momentum indicator. Smoothed DX
# **Default Inputs:** USEquityPricing.high, USEquityPricing.low, USEquitypricing.close
# **Default Window Length:** 29
# https://www.fidelity.com/learning-center/trading-investing/technical-analysis/technical-indicator-guide/DMI
inputs = [USEquityPricing.high, USEquityPricing.low, USEquityPricing.close]
true_length = 120 #Whatever length desired
window_length = true_length+true_length+1
def compute(self, today, assets, out, high, low, close):
# positive directional index
plus_di = 100 * np.cumsum(plus_dm_helper(high, low) / trange_helper(high, low, close), axis=0)
# negative directional index
minus_di = 100 * np.cumsum(minus_dm_helper(high, low) / trange_helper(high, low, close), axis=0)
# full dx with 15 day burn-in period
dx_frame = (np.abs(plus_di - minus_di) / (plus_di + minus_di) * 100.)[self.true_length:]
# 14-day EMA
span = float(self.true_length)
decay_rate = 2. / (span + 1.)
weights = weights_long = np.full(span, decay_rate, float) ** np.arange(span + 1, 1, -1)
# return EMA
out[:] = np.average(dx_frame, axis=0, weights=weights)