Skip to content

mabdullahsoyturk/trading-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

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:

Long

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.

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:

Short

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

Return

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:

API_KEY=<YOUR_API_KEY>
SECRET=<YOUR_SECRET>

Deploy

crontab -e
*/30  * * * * bash <repo_path>/run.sh >> <repo_path>/log.txt 2>&1

<repo_path> is the path where you cloned the repository.

About

An engulfing based crypto trading bot

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published