Skip to content

Instantly share code, notes, and snippets.

@dkav6
Created November 14, 2021 09:21
Show Gist options
  • Save dkav6/28075a01b15094a118160182c20f8547 to your computer and use it in GitHub Desktop.
Save dkav6/28075a01b15094a118160182c20f8547 to your computer and use it in GitHub Desktop.
class MLStrategy(Strategy):
n1=5
n2=10
def init(self):
self.sma1 = self.I(SMA, self.data.Close, self.n1)
self.sma2 = self.I(SMA, self.data.Close, self.n2)
def next(self):
if crossover(self.sma1, self.sma2) and self.data.target == 1:
self.buy()
elif crossover(self.sma2, self.sma1) and self.data.target == 0:
self.position.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment