Back

Stop Loss and Re-entry Condition

Hello all,

If I am running an ema cross-over with stop loss (self.StopMarketOrder) and the stop loss gets hit, is there a way to tell it to wait until the next cross-over occurs instead of opening another order? 

I only know how to re-enter the market after a certian number of days have passed, For example:

# Check that at least 14 days (~2 weeks) have passed since we last hit our limit order
if (self.Time - self.stopMarketFillTime).days < 14:
return

I would like to be able to re-enter the market on the next ema cross-over. Any ideas?

Thanks for reading.

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

We can place a lock on trading until our condition for new trades has been met. We can do this with a boolean which keeps track of whether trading has been locked or not.

Here is a simple 200-50 Day EMA cross over strategy with a trailing stop loss which employs this locking mechanism.

Best
Rahul

1

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.


 Thank you for sharing an example Rahul Chowdhury

Two quick questions about deploying an algorithm live:

- If my self.SetCash is set to $10,000 and my account has $20,000... will the algorithm use my full amount of $20,000 or only $10,000? all my order sizes are set to be x1.0 the SetCash but I just want to make sure lol

- If for whatever reason, my account gets disconnected to the algorithm with an open trade... can I deploy again the algorithm and it will take into consideration the open trades? (as long as they are symbols that get used in the algorithm)

- Anything to avoid when using Interactive Brokers as the brokerage where all trades will be taking place?

Please let me know if you need clarification on any of the questions.

Thanks again!

 

 

0

Hey Andres,

  • SetCash, SetStartDate, SetEndDate, etc are not taken into account in live mode. That means your account will use the full $20,000 as your intial cash balance.
  • The algorithm will always try to reconnect. If it cannot reconnect, it will exit with open positions. When you redeploy the algorithm, it will pick up the open orders.
  • There is nothing in particular you should avoid, although we recommend you start with an IB paper account first.
1

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