January 2020
Beginner to intermediate
432 pages
11h 24m
English
To make the code more readable, we first present the general outline of the class (trading strategy) and then define separate pieces in the following code blocks.
class SmaStrategy(bt.Strategy): params = (('ma_period', 20), ) def __init__(self): # some code def log(self, txt): # some code def notify_order(self, order): # some code def notify_trade(self, trade): # some code def next(self): # some code
The __init__ block is defined as:
def __init__(self): self.data_close = self.datas[0].close self.order = None self.price = None self.comm = None self.sma = bt.ind.SMA(self.datas[0], period=self.params.ma_period)
The log block is defined as:
def log(self, txt): dt = self.datas[0].datetime.date(0).isoformat() ...
Read now
Unlock full access