Back

Issue with "Identifying a Stop Loss Hit" in "Buy and Hold with a Trailing Stop" Boot Camp lesson

Hi,

I can't seem to get the "Identifying a Stop Loss Hit" part of the "Buy and Hold with a Trailing Stop" Boot Camp lesson to work, even when copying the solution verbatim (i.e. via copy-and-paste).

I get these errors in the console:

Exercise Hint: Looks like you're not waiting the required number of days to re-enter the market.
Exercise failed! Please try again.

 Does anyone else have this issue or is it something in my setup/account?

Update Backtest







0

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.


Hey Robot Trader, 

I had a similiar issue, the Exercise Hint is incorrect also.  I'll attack my full code that allowed me to pass the exercise, but the problem is probably creating and storing the stop market order. In the example 'ibmstockprice' must be calculated by grabbing the SPY equity close then multipliying by 0.90 'self.Securities['SPY'].Close * 0.90'.  When you debug the order ID you must include an additional 'self'.  'self.Debug(self.stopMarketTicket.OrderId) '. I am just learning as well so this explanation may not be totally correct, but this is what got the exercise to work for me.

Cheers, Redpoint

 

class BootCampTask(QCAlgorithm):
    
    # Order ticket for our stop order, Datetime when stop order was last hit
    stopMarketTicket = None
    stopMarketFillTime = datetime.min
    
    def Initialize(self):
        self.SetStartDate(2018, 12, 1)
        self.SetEndDate(2019, 4, 1)
        self.SetCash(100000)
        spy = self.AddEquity("SPY", Resolution.Daily)
        spy.SetDataNormalizationMode(DataNormalizationMode.Raw)
        
    def OnData(self, data):
    
        #4. Check that at least 15 days (~2 weeks) 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)

            #1. Create a stop market order, save the order ticket to stopMarketTicket
            self.stopMarketTicket = self.StopMarketOrder("SPY", -500, self.Securities['SPY'].Close * 0.90)
            self.Debug(self.stopMarketTicket.OrderId) 
            
            
    def OnOrderEvent(self, orderEvent):
        
        if orderEvent.Status != OrderStatus.Filled:
            return
        
        # Printing the security fill prices.
        self.Debug(self.Securities["SPY"].Close)
        
        #2. 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 orderEvent.OrderId == self.stopMarketTicket.OrderId:
            #3. Store datetime
            self.stopMarketFillTime = self.Time

1

 Is this tutorial in alpha, really poorly done. Even the solutions don't work, I am on the next exercise and highestSPYPrice is not calculated with no explanation on how to create the variable 

0

Sorry guys we're going to ship a new version of these this afternoon with the validation logic updated. The new re-write of bootcamp should be the same tests by just much more robost. ETA 6 more hours.... =)

2

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.


Appreciate the quick response Jared, looking forward to the re-write.

Thanks

0

Thanks Jared.  I should note that I'm doing the boot camp lessons in C#, in case that wasn't obvious from the C# badge on my profile image :-)

0

Update Backtest





0

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.


Loading...

This discussion is closed