- Maybe Provide a standard bot strategy for Bot...
- GUI if people were interested (could take a while I've no experience here)
- Speed up Data Set aligner in Backtester with multiprocessing
- Fix trailing Stop, think its causing some rounding errors.
- Heikin Ashi something like this
- Added a feature in the backtester that graphs all the trades made and Indicators at the time of the trade and saves them to folders labelled winning and losing trades, to help with analysis of strategies. (14/01/22) See below in the graph trades section.
- Updated Backtester to make it more user friendly & changed naming convention for saved data. (14/01/22)
- At the end of a backtest you can see the date & time that every trade was taken. So you can debug strategies by checking on tradingview/binance. (07/01/22)
Join My Discord Server & Follow The Twitter
- Utilizes python-Binance Client to execute orders and pull data from Binance
- Utilizes ta library for Technical indicators
- Write your own functions/classes to implement your TA strategies.
- There is no default Strategy implemented you must do this in Data_Set.py as specified below.
- Comes with some pre-coded strategies found in TradingStrats.py
- If you enjoy the repo please share it around to friends & tweet about it using the tweet button above 😃
or Buy me a Coffee - Min version = python 3.7
- Create a Binance Account (This link uses my referral which gives you 5% kickback on trades & would be greatly appreciated)
- Enable Two-factor Authentication in the security section to keep your crypto safe.
- Create a new API key under the API Management section.
- [✓] Read Info [✓] Enable Trading [✓] Enable Futures [X] Enable Withdrawals
- Whitelist your IP address to further secure your account, and so that your API keys don't expire after 1 month.
- Fill in your api keys into api_secret and api_key in API_keys.py.
Run strategies live in Bot.py
Run strategies at your own risk I am not responsible for your trading decisions, futures are risky and proper risk management should be adhered to at all times, always have a stoploss
There is no default strategy Currently, but one can be implemented in the data_set.py file in the make_Decision() function
- In Bot.py on line 341 are the settings.
- Choose the Interval you want to trade and the buffer of candlesticks your strategy will need.
- leverage and order_size should be changed acording to your preference
- symbol[] is a list of the symbols you wish to trade, the default is all the coins on the exchange currently.
- Trailing stop: set use_trailing_stop to 1 and change trailing_stop_percent to suit your strategy to use the trailing stop (Min val .001 i.e .1%, Max 5 i.e 5%). The trailing stop will be placed when the takeprofitval margin of increase/decrease is reached from your strategy.
Strategies are implemented in Data_Set.py as a function named Make_decision() in the Data_set class - Make_decision() must return Trade_Direction,stoplossval,takeprofitval for the strategy to work properly
- You might draw inspiration for a strategy from one In TradingStrats.py
Back test strategies in Backtester.py
- Create a list named 'symbol' of coin/coins you wish to run a strategy on ie. symbol = ['BTCUSDT' , 'ETHUSDT'] , this would run your strategy on BTC and ETH. Whereas symbol = ['BTCUSDT'] would run the strategy on BTC only.
- The data is split into an in-sample set and a test set, the flag test_set decides which set we are running the strategy on.
- The reason for splitting the data like this is to optimize parameters on the in-sample set and then once optimized run the strategy on the test-set to see if you have overfit your model by cherry picking values for parameters that suit the in-sample data.
- Settings are found at the top of the script, line 52.
- Trailing Stop: turn the use_trailing_stop flag on, specify the trailing_stop_distance in decimal, now when a takeprofit margin target is hit the trailing stop will be placed and automatically & adjusted based off new Lows or Highs in price and the trailing_stop_distance you've specified.
- Next we want to choose our TA strategy, this is done after line 640 , uncomment a strategy or call a new strategy you have written yourself here, the 'prediction' variable is used to tell the script to go short (0), go long (1), or go flat (-99). This should be returned by custom strategy functions/classes you write for the strategy to be executed correctly
- Some of the pre-coded strategies return a 'Type' variable, if a strategy returns the 'Type' variable you must call the SetSLTP() function from TradingStrats.py in order to set the corresponding Stop loss value, and Take profit value, this function is found in TradingStrats.py
- Now just run the script and wait a few minutes for it to pull the data and begin backtesting
- Heikin Ashi Candles are available under: CloseStream_H, OpenStream_H, LowStream_H, HighStream_H which can be referenced or passed to Strategies.
- Ensure your path in download_data.py is correct as specified.
- A folder will be made on your desktop named after the trade_graph_folder paramameter you provide.
- Settings should be easy to follow just change the flags and the indicators will be added to the graphs.
- Reason to do this is to speed up backtesting
- Create a folder on the desktop called price_data.
- In download_Data.py change the path to f"C:\Users\your_name\Desktop\
replacing your_name with the user that you are logged into. - Switch load_data on in Backtester.py on line 71, now when you run the script it will load from the folder & if the specified candlestick data isn't present in the folder then it will be downloaded and saved for future use.
- To overwrite existing data you can set the save_data flag = 1 & your data will be overwritten with new data.
- Otherwise you can just turn load_data off and pull data from the server everytime you want to run a backtest.
Not indicative of future returns, Check out the other backtests although results were poor on some that was due to transaction fees in many cases so maybe altering to take less trades or add confirmation could work. All of the strategies can be improved on but this is just a good place to start.
- If you have any querys about anything, or need me to explain any blocks of code please reach out to me at wconor539@gmail.com.
- If you have any suggestions or requests please reach out to me as well.
Join My Discord Server & Follow The Twitter