Back

Stop loss not triggering

Hello,

Thanks for anyone who can help.

I am an experienced trader, but a novice programmer.

When I try to back test, the stop loss does not trigger. **I have a 1% stop loss, but average loss is 1.51%**

Why does this stop loss not trigger?

Can anyone help me rewrite it so it works?

*****Thanks for your help. Please leave your paypal email, so I can thank you for ypur help.*****

 

Best wishes

 

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 Christian,

There's a few things going on in your code which I think are mistakes/incorrect. From top to bottom:

  • You say you have a stop loss of 1% but your stop_price variable is set to 2% of the open. Be careful in defining exactly what kind of stop loss you want and what price it should reference. I'm aware you're not using this variable anywhere in your code, but just pointing it out to you.
  • Your comments read "15 day" and "30 day" EMAs but you're not at all creating them with those parameters. Again, you're not even using the slow EMA but I just wanted to point this out to you in case you've missed it.
  • At the very end of your code, your if statement reads "if 99% of the close is more than the close, liquidate". That's never going to trigger, so if you're relying on that piece of your code to do the stop loss, then that explains why you're seeing greater average losses.
In general, for your sake and for the sake of the people on the forums who want to help, I would recommend you remove all the "fluff" from the code before posting it. That means all the comments, logs, debugs and unused variables/methods. First of all it makes it easier for you to potentially spot your own mistakes and secondly it makes it easier and faster for people to help you on the forums :) .
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