AI Strategy Generator

Describe Your Strategy
Describe your trading strategy in plain English, and our AI will generate the Python code for you using Backtrader.
Generated Python Code
Copy and use this code in your backtesting environment.

import backtrader as bt

class MyStrategy(bt.Strategy):
    def __init__(self):
        self.dataclose = self.datas[0].close
        self.order = None

    def next(self):
        if self.order:
            return
        if not self.position:
            if self.dataclose[0] < self.dataclose[-1]:
                self.order = self.buy()
        else:
            if len(self) >= (self.bar_executed + 5):
                self.order = self.sell()