Skip to content

Commit 1f3eb7a

Browse files
Merge pull request jesse-ai#11 from gabrielweich/donchian-strategy
add donchian strategy
2 parents 4e0962d + e8f4090 commit 1f3eb7a

6 files changed

+232
-0
lines changed

Donchian/ADA-USDT_6h_results.txt

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
loading candles...
2+
CANDLES |
3+
----------------------+--------------------------
4+
period | 731 days (2.0 years)
5+
starting-ending date | 2019-01-01 => 2021-01-01
6+
7+
8+
exchange | symbol | timeframe | strategy | DNA
9+
------------+----------+-------------+------------+-------
10+
Binance | ADA-USDT | 6h | Donchian |
11+
12+
13+
Executing simulation... [####################################] 100%
14+
Executed backtest simulation in: 34.98 seconds
15+
16+
17+
METRICS |
18+
---------------------------------+---------------------------
19+
Total Closed Trades | 19
20+
Total Net Profit | 55,272.4782 (552.72%)
21+
Starting => Finishing Balance | 10,000 => 65,272.48
22+
Total Open Trades | 1
23+
Open PL | 4,714.81
24+
Total Paid Fees | 1,277.14
25+
Max Drawdown | -36.15%
26+
Annual Return | 154.83%
27+
Expectancy | 2,909.08 (29.09%)
28+
Avg Win | Avg Loss | 8,936.79 | 1,474.71
29+
Ratio Avg Win / Avg Loss | 6.06
30+
Percent Profitable | 42%
31+
Longs | Shorts | 100% | 0%
32+
Avg Holding Time | 2 weeks, 2 days, 20 hours
33+
Winning Trades Avg Holding Time | 3 weeks, 2 days, 16 hours
34+
Losing Trades Avg Holding Time | 1 week, 4 days, 20 hours
35+
Sharpe Ratio | 1.68
36+
Market Change | 347.53%

Donchian/BAT-USDT_6h_results.txt

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
loading candles...
2+
CANDLES |
3+
----------------------+--------------------------
4+
period | 701 days (1.92 years)
5+
starting-ending date | 2019-05-05 => 2021-04-05
6+
7+
8+
exchange | symbol | timeframe | strategy | DNA
9+
------------+----------+-------------+------------+-------
10+
Binance | BAT-USDT | 6h | Donchian |
11+
12+
13+
Executing simulation... [####################################] 100%
14+
Executed backtest simulation in: 33.2 seconds
15+
16+
17+
METRICS |
18+
---------------------------------+---------------------------
19+
Total Closed Trades | 17
20+
Total Net Profit | 21,211.9829 (212.12%)
21+
Starting => Finishing Balance | 10,000 => 31,211.98
22+
Total Open Trades | 1
23+
Open PL | 177.78
24+
Total Paid Fees | 409.07
25+
Max Drawdown | -36.55%
26+
Annual Return | 80.73%
27+
Expectancy | 1,247.76 (12.48%)
28+
Avg Win | Avg Loss | 2,755.04 | 905.49
29+
Ratio Avg Win / Avg Loss | 3.04
30+
Percent Profitable | 59%
31+
Longs | Shorts | 100% | 0%
32+
Avg Holding Time | 2 weeks, 2 days, 22 hours
33+
Winning Trades Avg Holding Time | 2 weeks, 6 days, 18 hours
34+
Losing Trades Avg Holding Time | 1 week, 4 days, 12 hours
35+
Sharpe Ratio | 1.13
36+
Market Change | 224.43%

Donchian/BTC-USDT_6h_results.txt

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
loading candles...
2+
CANDLES |
3+
----------------------+--------------------------
4+
period | 731 days (2.0 years)
5+
starting-ending date | 2019-01-01 => 2021-01-01
6+
7+
8+
exchange | symbol | timeframe | strategy | DNA
9+
------------+----------+-------------+------------+-------
10+
Binance | BTC-USDT | 6h | Donchian |
11+
12+
13+
Executing simulation... [####################################] 100%
14+
Executed backtest simulation in: 35.53 seconds
15+
16+
17+
METRICS |
18+
---------------------------------+---------------------------
19+
Total Closed Trades | 18
20+
Total Net Profit | 45,194.3507 (451.94%)
21+
Starting => Finishing Balance | 10,000 => 55,194.35
22+
Total Open Trades | 1
23+
Open PL | 18,320.21
24+
Total Paid Fees | 760.56
25+
Max Drawdown | -46.89%
26+
Annual Return | 134.39%
27+
Expectancy | 2,510.8 (25.11%)
28+
Avg Win | Avg Loss | 5,824.01 | 1,630.71
29+
Ratio Avg Win / Avg Loss | 3.57
30+
Percent Profitable | 56%
31+
Longs | Shorts | 100% | 0%
32+
Avg Holding Time | 2 weeks, 6 days, 14 hours
33+
Winning Trades Avg Holding Time | 3 weeks, 6 days, 21 hours
34+
Losing Trades Avg Holding Time | 1 week, 4 days, 12 hours
35+
Sharpe Ratio | 2.03
36+
Market Change | 681.2%

Donchian/ETH-USDT_6h_results.txt

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
loading candles...
2+
CANDLES |
3+
----------------------+--------------------------
4+
period | 731 days (2.0 years)
5+
starting-ending date | 2019-01-01 => 2021-01-01
6+
7+
8+
exchange | symbol | timeframe | strategy | DNA
9+
------------+----------+-------------+------------+-------
10+
Binance | ETH-USDT | 6h | Donchian |
11+
12+
13+
Executing simulation... [####################################] 100%
14+
Executed backtest simulation in: 36.79 seconds
15+
16+
17+
METRICS |
18+
---------------------------------+--------------------------
19+
Total Closed Trades | 24
20+
Total Net Profit | 33,528.8877 (335.29%)
21+
Starting => Finishing Balance | 10,000 => 43,528.89
22+
Total Open Trades | 1
23+
Open PL | 5,487.64
24+
Total Paid Fees | 1,027.9
25+
Max Drawdown | -34.14%
26+
Annual Return | 108.22%
27+
Expectancy | 1,397.04 (13.97%)
28+
Avg Win | Avg Loss | 4,302.78 | 1,508.71
29+
Ratio Avg Win / Avg Loss | 2.85
30+
Percent Profitable | 50%
31+
Longs | Shorts | 100% | 0%
32+
Avg Holding Time | 2 weeks, 1 day, 4 hours
33+
Winning Trades Avg Holding Time | 3 weeks, 2 days, 8 hours
34+
Losing Trades Avg Holding Time | 1 week
35+
Sharpe Ratio | 1.53
36+
Market Change | 460.23%

Donchian/NEO-USDT_6h_results.txt

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
loading candles...
2+
CANDLES |
3+
----------------------+--------------------------
4+
period | 731 days (2.0 years)
5+
starting-ending date | 2019-01-01 => 2021-01-01
6+
7+
8+
exchange | symbol | timeframe | strategy | DNA
9+
------------+----------+-------------+------------+-------
10+
Binance | NEO-USDT | 6h | Donchian |
11+
12+
13+
Executing simulation... [####################################] 100%
14+
Executed backtest simulation in: 33.83 seconds
15+
16+
17+
METRICS |
18+
---------------------------------+------------------------------
19+
Total Closed Trades | 18
20+
Total Net Profit | 20,801.5637 (208.02%)
21+
Starting => Finishing Balance | 10,000 => 30,801.56
22+
Total Open Trades | 0
23+
Open PL | 0
24+
Total Paid Fees | 626.48
25+
Max Drawdown | -32.92%
26+
Annual Return | 75.23%
27+
Expectancy | 1,155.64 (11.56%)
28+
Avg Win | Avg Loss | 2,924.3 | 1,623.68
29+
Ratio Avg Win / Avg Loss | 1.8
30+
Percent Profitable | 61%
31+
Longs | Shorts | 100% | 0%
32+
Avg Holding Time | 2 weeks, 4 days, 2 hours
33+
Winning Trades Avg Holding Time | 3 weeks, 3 days, 14 hours
34+
Losing Trades Avg Holding Time | 1 week, 22 hours, 17 minutes
35+
Sharpe Ratio | 1.14
36+
Market Change | 92.41%

Donchian/__init__.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
Simple Donchian Strategy
3+
Repo: https://github.com/gabrielweich/jesse-strategies
4+
Uses Donchian Channels to capture long term uptrends, the idea is to buy
5+
when price closes above the upperband and only exit the position when
6+
prices closes below the lowerband.
7+
"""
8+
9+
from jesse.strategies import Strategy
10+
import jesse.indicators as ta
11+
from jesse import utils
12+
13+
14+
class Donchian(Strategy):
15+
@property
16+
def donchian(self):
17+
# Previous Donchian Channels with default parameters
18+
return ta.donchian(self.candles[:-1])
19+
20+
@property
21+
def ma_trend(self):
22+
return ta.sma(self.candles, period=200)
23+
24+
def filter_trend(self):
25+
# Only opens a long position when close is above 200 SMA
26+
return self.close > self.ma_trend
27+
28+
def filters(self):
29+
return [self.filter_trend]
30+
31+
def should_long(self) -> bool:
32+
# Go long if candle closes above upperband
33+
return self.close > self.donchian.upperband
34+
35+
def should_short(self) -> bool:
36+
return False
37+
38+
def should_cancel(self) -> bool:
39+
return True
40+
41+
def go_long(self):
42+
# Open long position using entire balance
43+
qty = utils.size_to_qty(self.capital, self.price, fee_rate=self.fee_rate)
44+
self.buy = qty, self.price
45+
46+
def go_short(self):
47+
pass
48+
49+
def update_position(self):
50+
# Close the position when candle closes below lowerband
51+
if self.close < self.donchian.lowerband:
52+
self.liquidate()

0 commit comments

Comments
 (0)