A strategy is a Python class that inherits from bt.Strategy. You write the class and pass it to cerebro.addstrategy(): Cerebro creates the object.
In __init__ you declare the indicators once, for example self.sma = bt.ind.SMA(self.data.close, period=20). Backtrader computes them over the whole series.
In next() you write each bar’s decision: if not self.position and self.data.close[0] > self.sma[0]: self.buy().
Settings go into params: params = (('period', 20),), then self.p.period. That way you can test 20, 50 or 100 without rewriting the class.
Examples
STRAT-X (fictional market) : The golden curve is the SMA 20 declared in __init__. In next(), the code buys when the price crosses above it and closes when it falls back below: each crossing is a decision of the strategy.
Knight Capital, 1 August 2012 : That day, a faulty software deployment at Knight Capital reactivated old trading code. In about 45 minutes the firm sent a flood of unintended orders and lost nearly 440 million dollars. Trading logic must be tested before it is trusted with the market.