-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
freeze_support error when creating a strategy #181
Comments
Found fix immediately before posting this, but decided to post as it might help someone else. Placing the code under the python main() function makes it work. Correct Code (in my case) import ccxt
from pprint import pprint
import pandas as pd
import pandas_ta as ta
def ccxt_ohlcv_to_dataframe(ohlcv):
""" Converts cctx ohlcv data from list of lists to dataframe. """
df = pd.DataFrame(ohlcv)
df.columns = ['time', 'open', 'high', 'low', 'close', 'volume']
df['date'] = pd.to_datetime(df['time'] * 1000000, infer_datetime_format=True)
return df
if __name__ == '__main__':
exchange = ccxt.binance()
ohlcv = exchange.fetch_ohlcv('BTC/USDT', '1d', limit=600)
df = ccxt_ohlcv_to_dataframe(ohlcv)
pprint(df)
# Create your own Custom Strategy
CustomStrategy = ta.Strategy(
name="Momo and Volatility",
description="SMA 50, 200, BBANDS, RSI, MACD and Volume SMA 20",
ta=[
{"kind": "sma", "length": 50},
{"kind": "sma", "length": 200},
{"kind": "bbands", "length": 20},
{"kind": "rsi"},
{"kind": "macd", "fast": 8, "slow": 21},
{"kind": "sma", "close": "volume", "length": 20, "prefix": "VOLUME"},
]
)
# To run your "Custom Strategy"
df.ta.strategy(CustomStrategy)
print(df.columns)
pprint(df.tail(20)) |
Hello @tudorelu, Happy New Year! Thanks for checking out Pandas TA! Glad you were able to quickly find the solution to Thanks, |
Thank you!!!!!!! |
Which version are you running?
0.2.28b0
Describe the bug
I am getting some OHLCV data from the ccxt library, saving it into a dataframe with the 'open', 'high', 'low', 'close' and 'volume' columns. The dataframe loks like this:
time open high low close volume date 0 1557705600000 6968.24 8100.0 6870.00 7790.71 85804.735333 2019-05-13 1 1557792000000 7795.62 8366.0 7599.56 7947.56 76583.722603 2019-05-14 2 1557878400000 7945.26 8249.0 7850.00 8169.87 37884.327211 2019-05-15 3 1557964800000 8169.08 8320.0 7705.00 7866.59 69630.513996 2019-05-16 4 1558051200000 7868.67 7925.0 6913.00 7355.26 88752.008159 2019-05-17 .. ... ... ... ... ... ... ... 595 1609113600000 26281.54 27500.0 26101.00 27079.41 79721.742496 2020-12-28 596 1609200000000 27079.42 27410.0 25880.00 27385.00 69411.592606 2020-12-29 597 1609286400000 27385.00 28996.0 27320.00 28875.54 95356.057826 2020-12-30 598 1609372800000 28875.55 29300.0 27850.00 28923.63 75508.505152 2020-12-31 599 1609459200000 28923.63 29470.0 28690.17 29296.28 25362.458601 2021-01-01
I then create a strategy with a few indicators and try to run it on the dataframe.
Running the following code works perfectly from the python command line, however saving it into a file and running it from there enters an infinite loop, where an error is printed.
To Reproduce
Error Message
Expected behavior
I would expect it to work fine when caling from a file, as it does from the python command line.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
I am using a virtual environment (venv).
Note: If I add "col_names" to even one indicator, the code prints the error once or twice but then returns the correct dataframe:
I also tried importing freeze_support from multiprocessing and calling the function at the beginning of the file, to no avail.
The text was updated successfully, but these errors were encountered: