For some reason when I put in my RollingWindow it creates a no-trade situation but when I take it out the program will buy and hold. I’ve watched the videos a few times and read the Historical Data articles, but I still can’t make this work for some reason. The back-test does not throw an error, so I'm confused about what I am missing. Any help would be appreciated.
def Initialize(self):
self.SetStartDate(2020, 1, 1)
self.SetEndDate(2023, 9, 15)
self.SetCash(3000)
self.SettingsFreePortfolioValuePercentage = 10
self.SetExecution(ImmediateExecutionModel())
self.symbol = self.AddEquity("SPY", Resolution.Daily, dataNormalizationMode=DataNormalizationMode.Raw).Symbol
self.SetWarmUp(timedelta(7))
def OnData(self, data):
if self.IsWarmingUp: return
else:
quantity = self.CalculateOrderQuantity(self.symbol, 0.4)
trade_bars = self.History[TradeBar](self.symbol, 7)
self.close_window = RollingWindow[float](7)
self.close_window.Add(data[self.symbol].Close)
self.close_window.Size = 5
if not self.close_window.IsReady: return
else:
current_close = self.close_window[0]
oldest_close = self.close_window[self.close_window.Count-1]
if not self.Portfolio.Invested: self.MarketOrder(self.symbol, quantity)
+ Expand- Collapse
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!