An engulfing based crypto trading bot
A trading bot that I've used for a while
This repository contains a trading bot that I used in Binance for a while. It's for educational purposes. Even though, the strategy seems profitable, I don't advise or recommend you to use it. Get a professional help for that.
Project Structure
trading-bot/
backtest/ # Backtesting package
backtesting.py
summary.py
data/ # Dataclasses
ohlcv.py # (O)pen, (H)ighest, (L)owest, (C)lose, (V)olume
order.py # Contains order info
position.py # Contains position info
strategies/ # Contains different strategies
engulfing.py # Main engulfing strategy that I use
macd.py # An macd based strategy
strategy.py # Abstract strategy class
main.py # Main file to execute the bot
run.sh # Script for crontab
Strategy
Long Strategy
Requirements:
- Price is above 200 EMA
- Two red candles, followed by an engulfing green candle.
- The price move of engulfing candle is no more than 2 times ATR.
- Entry price: Closing of engulfing candle.
- Stop price: Lowest price of either engulfing or lowest price of the candle before engulfing candle (whichever is lower).
Long example:

Short Strategy
Requirements:
- Price is below 200 EMA
- Two green candles, followed by an engulfing red candle.
- The price move of engulfing candle is no more than 2 times ATR.
- Entry price: Closing of engulfing candle.
- Stop price: Highest price of either engulfing or highest price of the candle before engulfing candle (whichever is higher).
Short example:

Backtest Results
TIMEFRAME = 30m RR = 2 EMA = 200 ATR = 2
You can run the following backtest with:
python main.py --backtest --days-ago 370 --ema-timeperiod 200 --rr 2 --timeframe 30m atr-multiplier 2
| Side | Total R | Win Rate | Num Stops | Num Profits | Num Positions | | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | | LONG | 51 | 0.405 | 141 | 96 | 237 | | SHORT | 95 | 0.395 | 309 | 202 | 512 |
| Side | Longest Winning Streak | Longest Losing Streak | | ------------- | ------------- | ------------- | | LONG | 10 | 8 | | SHORT | 14 | 17 |

Install Dependencies
pip install -r requirements.txt
Setup your API_KEY and SECRET
Put your API_KEY and SECRET in a new .env file.
Example:
APIKEY=<YOURAPI_KEY>
SECRET=<YOUR_SECRET>
Deploy
crontab -e
/30 * bash <repopath>/run.sh >> <repopath>/log.txt 2>&1