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.
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
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.
Position info:
- 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).
- Take profit price: Entry Price + rr * (Entry Price - Stop Price)
Long example:
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.
Position info:
- 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).
- Take profit price: Entry Price + rr * (Stop Price - Entry Price)
Short example:
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 |
pip install -r requirements.txt
Put your API_KEY and SECRET in a new .env file.
Example:
API_KEY=<YOUR_API_KEY>
SECRET=<YOUR_SECRET>
crontab -e
*/30 * * * * bash <repo_path>/run.sh >> <repo_path>/log.txt 2>&1
<repo_path> is the path where you cloned the repository.