def signal_function(px, params):
    """
        The main trading logic goes here, called by generate_signals above
    """
    upper, mid, lower = bollinger_band(px, params['BBands_period'])
    last_px = px[-1]
    dist_to_upper = 100 * (upper - last_px) / (upper - lower)

    if dist_to_upper > 95:
        return 1
    elif dist_to_upper < 5:
        return -1
    else:
        return 0
def signal_function(px, params, last_signal):
    """
        The main trading logic goes here, called by generate_signals above
    """
    ind1 = doji(px)
    upper, mid, lower = bollinger_band(px.close.values,
                                       params['BBands_period'])
    last_px = px.close.values[-1]
    dist_to_upper = 100 * (upper - last_px) / (upper - lower)

    if ind1 > 0 and dist_to_upper < 30:
        return 1
    elif ind1 > 0 and dist_to_upper > 70:
        return -1
    else:
        return last_signal
def signal_function(px, params):
    """
        The main trading logic goes here, called by generate_signals above
    """
    upper, mid, lower = bollinger_band(px, params['BBands_period'])
    ind2 = ema(px, params['SMA_period_short'])
    ind3 = ema(px, params['SMA_period_long'])
    last_px = px[-1]
    dist_to_upper = 100 * (upper - last_px) / (upper - lower)

    if dist_to_upper > 95:
        return -1
    elif dist_to_upper < 5:
        return 1
    elif dist_to_upper > 40 and dist_to_upper < 60 and ind2 - ind3 < 0:
        return -1
    elif dist_to_upper > 40 and dist_to_upper < 60 and ind2 - ind3 > 0:
        return 1
    else:
        return 0