Python: How to enter limit order with take profit

Hi community,

I am new to this exciting platform and want to build a simple grid trading system.

My first step is to create a limit order with a take profit.

How to place a limit order at a fixed price with a take profit?

I wrote this for a limit order:

newTicket = self.LimitOrder("AUDCAD", 1000, 0.97)

I want to buy 1000 units of AUDCAD at a price of 0.97$

Now I need to add a take profit of 50 pips to my order. How to do that?

Thanks in advance!

Cheers, Robert

Update Backtest

Once the order is filled, you can place a limit sell order to take the profit. is a list to save the old order tickets so you can retrieve the ticket in the next time loop. Once the limit buy order is filled, empty the list.

# In initialize() = []
# In OnData()
ticket = self.LimitOrder("AUDCAD", 1000, 0.97)
if[0].Status == OrderStatus.Filled:
self.LimitOrder("AUDCAD", -1000,[0].AverageFillPrice+0.05) = []

Update Backtest


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.


This discussion is closed