I am self taught in Python but am still in the process of mastering it. I was told that the best way to learn is by doing so I have already been applying it anyway to this excellent website. All I need to know is how to prevent trades from triggering multiple times during Moving Average crossover strategies - or in that case any type of crossover strategy. Is there a way to require a certain percentage gain/loss from the previously opened position that would cancel the next crossover trade. Also would love to simply just limit activity to one buy and sell per security, per day.

#All Hail NASDAQ

class SamAlgorythm:

def Initialize(self):
self.SetStartDate(2013, 12, 1) # 2013/12/01 Earliest start date for selected ETFs
self.SetEndDate(2020, 6, 4)
self.SetCash(250000000) # Idk how to adjust for the 1000 splits TVIX has done
self.SetWarmup(100)
self.SetBenchmark("QQQ")
self.AddEquity("QQQ", Resolution.Hour)
self.AddEquity("TQQQ", Resolution.Hour) # 3x QQQ
self.AddEquity("TVIX", Resolution.Hour) # 2x VIX (er sumthin)
self.mothersma = self.SMA("QQQ", 25, Resolution.Hour)
self.othersma = self.SMA("QQQ", 75, Resolution.Hour)

def OnData(self, data):
if self.mothersma.Current.Value > self.othersma.Current.Value:
self.SetHoldings("TQQQ", 1) and self.SetHoldings("QQQ", 0) and self.SetHoldings("TVIX", 0)
elif self.mothersma.Current.Value <= self.othersma.Current.Value:
self.Liquidate("TQQQ")
self.SetHoldings("QQQ", 0.5) and self.SetHoldings("TVIX", 0.075)
else:
self.Liquidate("TQQQ") and self.Liquidate("QQQ") and self.Liquidate("TVIX")

Thanks in advance for any help and I look forward to eventually becoming a contributing member of this community!