Hi everyone, I am receiving the error posted in the title. My understanding is algorithm data is pumped in according to resolution and can be passed into other methods/functions as parameters. However, I seem to get this error when passing the data into my scheduled methods/functions. Any suggestions on what could be causing this or fixes?
class PowerHourTest(QCAlgorithm):
openingPrice = 0
tradeLock = False
def Initialize(self):
self.SetStartDate(2022, 1, 1)
self.SetEndDate(2022, 3, 18)
self.SetCash(100000)
self.ticker = "QQQ"
self.symbol = self.AddEquity(self.ticker, Resolution.Minute).Symbol
self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage)
self.SetRiskManagement(TrailingStopRiskManagementModel(0.01))
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen(self.symbol, 1), self.OpeningBellPriceCapture)
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.At(14, 0), self.PowerHourTradeExecution)
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.BeforeMarketClose(self.symbol, 1), self.SellOnClose)
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.At(23, 59), self.TradeLockReset)
def OnData(self, data):
return
def OpeningBellPriceCapture(self, data):
self.openingPrice = data.Bars[self.symbol].Open
def PowerHourTradeExecution(self, data):
if self.openingPrice == 0:
return
self.currentPrice = data.Bars[self.symbol].Close
if self.currentPrice - self.openingPrice < 0 and self.tradeLock is False:
self.SetHoldings(self.symbol, 1)
self.tradeLock = True
def SellOnClose(self):
self.Liquidate
def TradeLockReset(self):
self.openingPrice = 0
self.tradeLock = False
Vladimir
James Hawkins,
Try this way
James Hawkins
Vladimir works like a charm, thank you!
James Hawkins
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
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!