index 0 is out of bounds for axis 0 with size 0
phpmac opened this issue · comments
import ccxt
import pandas as pd
from smartmoneyconcepts import smc
exchange = ccxt.binanceusdm(
{
"apiKey": "1",
"secret": "1",
"enableRateLimit": True,
}
)
# exchange.verbose = True
exchange.options["warnOnFetchOpenOrdersWithoutSymbol"] = False
klines = exchange.fetch_ohlcv("POLYX/USDT", "1h", limit=100)
# 转为 df
df = pd.DataFrame(
klines, columns=["timestamp", "open", "high", "low", "close", "volume"]
)
swing_highs_lows = smc.swing_highs_lows(df, 50)
print(swing_highs_lows)
# fvg_data = smc.fvg(df)
# df = pd.concat([df, fvg_data], axis=1)
# swing_highs_lows = smc.swing_highs_lows(df)
# print(swing_highs_lows)
# print(df)
Hello @joshyattridge , I have exactly the same issue.
I have tried resetting the dataframe indexes to integers, and also truncating it, but it didn't help at all.
...
File "..\venv\lib\site-packages\smartmoneyconcepts\smc.py", line 34, in wrap
return func(*args, **kwargs)
File "..\venv\lib\site-packages\smartmoneyconcepts\smc.py", line 192, in swing_highs_lows
if swing_highs_lows[positions[0]] == 1:
IndexError: index 0 is out of bounds for axis 0 with size 0
FYI, here's the content of my ohlc dataframe (pretty-printed):
datetime | open | high | low | close |
---|---|---|---|---|
2024-04-08 23:01:00-04:00 | 71430.5 | 71468 | 71420.6 | 71420.6 |
... | ... | ... | ... | ... |
Hi @phpmac @narmaku, look at the tests you need to call df = df.iloc[:, :6]
on the DataFrame:
iloc: Purely integer-location based indexing for selection by position.
def import_data(symbol, start_str, timeframe):
client = Client()
start_str = str(start_str)
end_str = f"{datetime.now()}"
df = pd.DataFrame(
client.get_historical_klines(
symbol=symbol, interval=timeframe, start_str=start_str, end_str=end_str
)
).astype(float)
df = df.iloc[:, :6]
df.columns = ["timestamp", "open", "high", "low", "close", "volume"]
df = df.set_index("timestamp")
df.index = pd.to_datetime(df.index, unit="ms").strftime("%Y-%m-%d %H:%M:%S")
return df
Thanks @VioletEsfenaj. I was already using iloc.
So I think the issue was the fact that I was passing a very high swing_length.
My DataFrame contains candles from the last 60 minutes (1-min candles). So I guess I need to pass a very small swing_length value. I tried with 5 and 3 and it worked well, apparently.
This error occurs when the "swing_length" is too large for the amount of candles provided, so you will either need to reduce the "swing_length" or increase the amount of candles you provide the "swing_highs_lows" function.
This error has been managed in the latest change.