0

我正在尝试将此 pinescript 函数转换为 python,但无法弄清楚我做错了什么。我也很有限,因为我不能使用 Numpy 和 Pandas。

f_pmarp ( _price, _pmarLen, _pmarpLen, _type ) =>
    _pmar = math.abs ( _price / f_ma_val ( _price, _type, _pmarLen ))
    _pmarpSum = 0
    _len = bar_index < _pmarpLen ? bar_index : _pmarpLen
    for i = 1 to _len by 1
        _pmarpSum += ( _pmar[i] > _pmar ? 0 : 1 )
        _pmarpSum
    _return = bar_index >= _pmarLen ? _pmarpSum / _len * 100 : na

这是我到目前为止所做的,但我似乎无法获得与 pinescript 函数相同的结果。任何想法?

def pmarp(prices, vol, malen, pmarplen, type):
    #Price Moving Average Ratio Percentile

    j = pmarplen + malen
    result = []
    while j < len(prices):
        p = prices[-j:]
        if type == 'TEMA':
            ma = tema(p, malen)
        elif type == 'VWMA':
            ma = vwma(p, vol, malen)
        elif type == 'EMA':
            ma = ema(p, malen)
        else:
            return 0

        _pmar = []
        for num1, num2 in zip(p[-len(ma):],ma):
            _pmar.append(math.fabs(num1 / num2))
        _pmarpSum = 0
        i = 1
        while i < pmarplen:
            if _pmar[-1] >= _pmar[i]:
                _pmarpSum += 1
            i += 1

        result.append(_pmarpSum / pmarplen * 100)
        j += 1
    return result
4

0 回答 0