Hi, anyone has this problem with Buy & Hold with a Trailing Stop Tutorial 3/5 and 4/5?
It returns AttributeError : 'NoneType' object has no attribute 'OrderId'.
Thank you
QUANTCONNECT COMMUNITY
Hi, anyone has this problem with Buy & Hold with a Trailing Stop Tutorial 3/5 and 4/5?
It returns AttributeError : 'NoneType' object has no attribute 'OrderId'.
Thank you
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.
Shile Wen
Hi Jin,
I was unable to reproduce the error message. Please retry and let us know whether it still happens to you.
Best,
Shile wen
Jin Rong Loo
Hi, I still face problem completing the task. Here are my codes:
class BootCampTask(QCAlgorithm):
#Order ticket for stop order, Datetime when stop order was last hit
stopMarketTicket = None
stopMarketFillTime = datetime.min
def Initialize(self):
self.SetCash(100000)
self.SetStartDate(2017, 6, 1)
self.SetEndDate(2017, 6, 30)
spy = self.AddEquity("SPY", Resolution.Daily)
spy.SetDataNormalizationMode(DataNormalizationMode.Raw)
def OnData(self, data):
#Check that at least 15 days have passed since we last hit our stop order
if (self.Time - self.stopMarketFillTime).days < 15:
return
if not self.Portfolio.Invested:
self.MarketOrder("SPY", 500)
#Create stop loss through a stop market order
self.stopMarketTicket = self.StopMarketOrder("SPY", -500, 0.9 * self.Securities["SPY"].Close)
def OnOrderEvent(self, orderEvent):
if orderEvent.Status != OrderStatus.Filled:
return
#Printing the security fill prices
self.Debug(self.Securities["SPY"].Close)
#Check if we hit our stop loss (Compare the orderEvent.Id with the stopMarketTicket.OrderId)
#It's important to first check if the ticket isn't null (i.e. making sure it has been submitted)
if self.stopMarketTicket is not None and self.stopMarketTicket.OrderId == orderEvent.OrderId:
#Store datetime
self.stopMarketFillTime = self.Time
self.Debug(self.stopMarketFillTime)
Shile Wen
Hi Jin,
The start and end dates were changed from what was in the tutorial. I suggest using self.SetStartDate(2018, 12, 1) and self.SetEndDate(2019, 4, 1)
Best,
Shile Wen
Jin Rong Loo
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!