如何用Python将OHLC值转换为Renko图表?

问题描述 投票:1回答:1

在过去的几个小时里,我一直在尝试匹配Tradingview上的Renko图表,但似乎仍然无法找出我做错了什么。

到目前为止,除了趋势逆转的情况外,我的算法吐出了正确的值。

import math
import pandas as pd


def bricks_series(df: pd.DataFrame, step=50):
    prices = df['close']
    first_brick = math.floor(prices.iloc[0] / step) * step
    bricks = [first_brick]
    for price in prices:
        if price > (bricks[-1] + step):
            step_mult = math.floor((price - bricks[-1]) / step)
            next_bricks = [bricks[-1] + (mult * step) for mult in range(1, step_mult + 1)]
            bricks += next_bricks
        elif price < bricks[-1] - step:
            step_mult = math.ceil((bricks[-1] - price) / step)
            next_bricks = [bricks[-1] - (mult * step) for mult in range(1, step_mult + 1)]
            bricks += next_bricks
        else:
            continue
    return bricks


if __name__ == "__main__":
    df = pd.read_csv("binance_daily.csv")
    renko_bricks = bricks_series(df)

这是我的ohlc数据。https:/drive.google.comopen?id=1Psn8XYBwJ9F5JCTpF0ffxQx_vcLSFyD4。

而这是我试图复制的图表。https:/www.tradingview.comchartlyXNhcbs

python pandas time-series algorithmic-trading
1个回答
0
投票

你可以用那个作为例子。https:/github.comcarlfartersonTAchartsblobmasterTAchartsindicatorsrenko.py。

我测试了它,它的工作原理很好。和tradingview不完全一样,所以也许你要调整一下。

© www.soinside.com 2019 - 2024. All rights reserved.