Back

Stop and take profit

I need to know why my take profit and stop orders don't work.

thank you

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.


maybe some other posts will help you get some ideas:

https://www.quantconnect.com/forum/discussion/1539/how-to-place-three-way-order

 

https://www.quantconnect.com/forum/discussion/5270/futures-bracket-orders-with-multiple-symbols

 

0

Hi Patrik.

In the method OnData(), you have:

stop_price_ = self.Securities['EURUSD'].Price * 0.89
stop_price = self.Securities['EURUSD'].Price * 1.13

if price <= self.Bolband.LowerBand.Current.Value:
self.SetHoldings("EURUSD", 0.2)
self.LimitOrder("EURUSD", holdings, stop_price_)
self.StopMarketOrder("EURUSD", holdings, stop_price)

Set Take-Profit level used in LimitOrder() higher than the market price, and set the Stop-Loss level lower than the market price. Also, calculate quantity for LimitOrder() and StopMarketOrder() after entering a position:

if price <= self.Bolband.LowerBand.Current.Value:
self.SetHoldings("EURUSD", 0.2)
holdings = self.Portfolio["EURUSD"].Quantity
self.LimitOrder("EURUSD", -holdings, stop_price)
self.StopMarketOrder("EURUSD", -holdings, stop_price_)

I've attached a backtest where I demonstrate how to use LimitOrder() and StopMarketOrder(), using your code as a template. Check out this documentation section on Tracking and Managing Orders for further information.

1


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