Skip to content

Commit

Permalink
+ added multiple SMA support
Browse files Browse the repository at this point in the history
  • Loading branch information
WISEPLAT committed Jun 6, 2022
1 parent 8f731c1 commit 389531c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions StrategySMA_EMA_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def next(self):
self.log(f'{ticker} - {bt.TimeFrame.Names[data.p.timeframe]} {data.p.compression} - Open={data.open[0]:.2f}, High={data.high[0]:.2f}, Low={data.low[0]:.2f}, Close={data.close[0]:.2f}, Volume={data.volume[0]:.0f}',
bt.num2date(data.datetime[0]))
# print("[", ticker, self.sma1[0], self.sma2[0], "]")
print("[", ticker, self.sma_all1[ticker][0], self.sma_all2[ticker][0], "]")
# print("[", ticker, self.sma_all1[ticker][0], self.sma_all2[ticker][0], "]")


# # https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib
Expand All @@ -90,13 +90,13 @@ def next(self):

if not self.orders[ticker]:
if self.sma_all1[ticker][0] > self.sma_all2[ticker][0]:
self.log('BUY CREATE, %.2f' % self.data.close[0])
self.log(f"BUY CREATE [{ticker}] {self.data.close[0]:.2f}")
self.buy(data=data, exectype=bt.Order.Market) # , size=size)
self.orders[ticker] = True

if self.orders[ticker]:
if self.sma_all1[ticker][0] < self.sma_all2[ticker][0]:
self.log('SELL CREATE, %.2f' % self.data.close[0])
self.log(f"SELL CREATE [{ticker}] {self.data.close[0]:.2f}")
self.sell(data=data, exectype=bt.Order.Market) # , size=size)
self.orders[ticker] = False

Expand All @@ -118,9 +118,9 @@ def notify_order(self, order):
# Attention: broker could reject order if not enough cash
if order.status in [order.Completed]:
if order.isbuy():
self.log('BUY EXECUTED, %.2f' % order.executed.price)
self.log(f"BUY EXECUTED [{order.data._name}], {order.executed.price:.2f}")
elif order.issell():
self.log('SELL EXECUTED, %.2f' % order.executed.price)
self.log(f"SELL EXECUTED [{order.data._name}], {order.executed.price:.2f}")

self.bar_executed = len(self)
self.orders_bar_executed[order.data._name] = len(self)
Expand Down

0 comments on commit 389531c

Please sign in to comment.