BootCamp - > Buy and Hold with a Trailing Stop -> Understanding Order Events

Back

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;
        } 
    }
}

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.


Hi Nelson,

Thanks for reporting this. I just re-tested this BootCamp, and it seems to be working again, however, please update if you are still having issues with this BootCamp.

Best,
Shile Wen

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.


Hi Shile,

For me it's still not working.

Regards,

Amaury

0

Hi Nelson,

Thanks for reporting this. We will look into the cause of the issue.

Best,
Shile Wen

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.


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