Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
update backtrader test script
Browse files Browse the repository at this point in the history
add bollinger band strategy
add eth-usd data
  • Loading branch information
CelestialCrafter committed Dec 4, 2023
1 parent 3e1e818 commit 00871fd
Show file tree
Hide file tree
Showing 3 changed files with 407 additions and 7 deletions.
19 changes: 19 additions & 0 deletions algorithms/bollinger_bands.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import backtrader as bt
from talib import BBANDS
from price import get_periods, get_max_periods

Expand All @@ -18,3 +19,21 @@ def signal(prices, data):
return 'buy', 0.5

return 'no_action', 0

class Strategy(bt.Strategy):
params = (('timeperiod', 20), ('nbdev', 2.0))

def __init__(self):
indicator = bt.talib.BBANDS(self.data.close,
timeperiod=self.p.timeperiod,
nbdevup=self.p.nbdev,
npdevdn=self.p.nbdev)

self.close_over_upper_band = self.data.close > indicator.upperband
self.close_under_lower_band = self.data.close < indicator.lowerband

def next(self):
if self.close_over_upper_band:
self.sell()
elif self.close_under_lower_band:
self.buy()
Loading

0 comments on commit 00871fd

Please sign in to comment.