Trying to finish this exercise but it kept failing. I even copied the solution but it keeps failing.

The code is :

namespace QuantConnect
{
    public partial class BootCampTask : QCAlgorithm
    {
        OrderEvent lastOrderEvent;
        
        public override void Initialize()
        {
            SetStartDate(2018, 12, 1);
            SetEndDate(2019, 4, 1);
            SetCash(100000);
            var spy = AddSecurity(SecurityType.Equity, "SPY", Resolution.Daily);
            spy.SetDataNormalizationMode(DataNormalizationMode.Raw);
        }

        public override void OnData(Slice slice)
        {
            if (!Portfolio.Invested) 
            {
                MarketOrder("SPY", 500);
                StopMarketOrder("SPY", -500, 0.90m * Securities["SPY"].Close);
            }
        }

        public override void OnOrderEvent(OrderEvent orderEvent)
        {
            //Some debugging to assist you.
            Debug(orderEvent.ToString());

            //1. Write code to only act on fills
            if(orderEvent.Status!=OrderStatus.Filled)
            {
                return;
            }
            
            //2. Use debug to print the order id, and save the order event to lastOrderEvent
            lastOrderEvent = orderEvent;
        } 
    }
}

Author