来自 talib python 库的 MFI 指标没有 return 任何值
MFI indicator from talib python library doesn`t return any value
def on_message(ws, message):
global in_position
global closes
json_message = json.loads(message)
candle = json_message['k']
is_candle_closed = candle['x']
close = candle['c']
high = candle['h']
low = candle['l']
volume = candle['V']
if is_candle_closed:
print("Candle closed at {}".format(close))
highs.append(float(high))
lows.append(float(low))
closes.append(float(close))
volumes.append(float(volume))
print(':')
if len(closes) > MFI_PERIOD:
np_closes = numpy.array(closes)
mfi = talib.MFI(highs, lows, np_closes, volumes, MFI_PERIOD)
last_mfi = mfi[-1]
print('The current (MIDPOINT) is {}'.format(last_mfi))
-im using binance websocket stream to get kline data -i
m 试图从 MFI(资金流量指数)获取数据或值以实现某些交易的自动化
+我尝试了其他指标,例如 RSI 并且有效
- 但我不
t know why this one isn
t
这是一个简单的解决方案,您必须将值转换为 numpy 数字才能用作 talib.MFI
的参数
...
if len(closes) > MFI_PERIOD:
np_closes = numpy.array(closes)
np_highs = numpy.array(highs)
np_lows = numpy.array(lows)
np_volumes = numpy.array(volumes)
mfi = talib.MFI(np_highs, np_lows, np_closes, np_volumes, MFI_PERIOD)
last_mfi = mfi[-1]
print('The current (MIDPOINT) is {}'.format(last_mfi))
我正在做同一个项目,它对我有用。
def on_message(ws, message):
global in_position
global closes
json_message = json.loads(message)
candle = json_message['k']
is_candle_closed = candle['x']
close = candle['c']
high = candle['h']
low = candle['l']
volume = candle['V']
if is_candle_closed:
print("Candle closed at {}".format(close))
highs.append(float(high))
lows.append(float(low))
closes.append(float(close))
volumes.append(float(volume))
print(':')
if len(closes) > MFI_PERIOD:
np_closes = numpy.array(closes)
mfi = talib.MFI(highs, lows, np_closes, volumes, MFI_PERIOD)
last_mfi = mfi[-1]
print('The current (MIDPOINT) is {}'.format(last_mfi))
-im using binance websocket stream to get kline data -i
m 试图从 MFI(资金流量指数)获取数据或值以实现某些交易的自动化
+我尝试了其他指标,例如 RSI 并且有效
- 但我不
t know why this one isn
t
这是一个简单的解决方案,您必须将值转换为 numpy 数字才能用作 talib.MFI
的参数...
if len(closes) > MFI_PERIOD:
np_closes = numpy.array(closes)
np_highs = numpy.array(highs)
np_lows = numpy.array(lows)
np_volumes = numpy.array(volumes)
mfi = talib.MFI(np_highs, np_lows, np_closes, np_volumes, MFI_PERIOD)
last_mfi = mfi[-1]
print('The current (MIDPOINT) is {}'.format(last_mfi))
我正在做同一个项目,它对我有用。