def long_short_signal_crosses(prices, short_period=DEFAULT_SHORT_PERIOD, long_period=DEFAULT_LONG_PERIOD):
    num_prices = len(prices)
    long_period = min(long_period, num_prices)
    if short_period == DEFAULT_SHORT_PERIOD:
        short_period = min(short_period, num_prices, int(round(.46*long_period)))
    long_ma  = ewmas(prices, long_period)
    short_ma = ewmas(prices, short_period)

    # lists must be the same length
    short_ma = short_ma[len(short_ma)-len(long_ma):len(short_ma)]

    return signal_crosses(short_ma, long_ma)
Пример #2
0
def ema_ma_signal_crosses(prices, ema_period=DEFAULT_EMA_PERIOD, ma_period=False):
    ma_period = ma_period or ema_period
    num_prices = len(prices)
    ma_period = min(ma_period, num_prices)
    if ema_period == DEFAULT_EMA_PERIOD:
        ema_period = min(ema_period, num_prices, int(round(.46*ma_period)))
    ma  = ewmas(prices, ma_period)
    ema = ewmas(prices, ema_period)

    # lists must be the same length
    ema = ema[len(ema)-len(ma):len(ema)]

    return signal_crosses(ema, ma)
def long_short_signal_crosses(prices,
                              short_period=DEFAULT_SHORT_PERIOD,
                              long_period=DEFAULT_LONG_PERIOD):
    num_prices = len(prices)
    long_period = min(long_period, num_prices)
    if short_period == DEFAULT_SHORT_PERIOD:
        short_period = min(short_period, num_prices,
                           int(round(.46 * long_period)))
    long_ma = ewmas(prices, long_period)
    short_ma = ewmas(prices, short_period)

    # lists must be the same length
    short_ma = short_ma[len(short_ma) - len(long_ma):len(short_ma)]

    return signal_crosses(short_ma, long_ma)