class TestStrategy(Strategy): short_sma_period = 5 short_close_period = 5 def init(self): self.SMA = self.I(talib.SMA, pd.Series(self.data.Close), self.short_sma_period) self.CLOSE_SMA = self.I(talib.SMA, pd.Series(self.data.Close), self.short_close_period) def next(self): if crossover(self.data.Close, self.SMA): self.buy() if self.position and crossover(self.CLOSE_SMA, self.data.Close): self.position.close() #### Define your optimization variables here##### def main(): #do the initial stuff (days_back, period, information) = get_initial_variables() forex_data = get_forex_data(days_back=days_back, period=period) bt = Backtest(forex_data, TestStrategy, cash=10000, commission=.000) stats, heatmap = bt.optimize(short_sma_period=range(10,200),short_close_period=range(10,200),return_heatmap=True) print (stats, heatmap) if __name__ == "__main__": main()