Back

Making a trailing stop with StopMarketOrder()?

We are trying to implement trailing stops for Long and Short orders.

We were doing simple if/else statements to keep track of a the high-water mark (or low water mark in a short), but it seems the correct way would be using the StopMarketOrder() function, and then doing an UpdateOrderFields() as this will be more accurate (and stateless). What confuses me, si that all the documentation around StopMarketOrder() says you set it HIGHER than the current market price, which isn't what we want a trailing stop for (we want it as a way to cap our downside).

Is this correct? Or have I misunderstood the StopMarketOrder() purpose?

Thanks!
 

Update Backtest








Somebody may correct me, but both, LimitOrder and StopMarketOrder, can be used below and above the price, the main difference between them is that LimitOrder is a "execute only with profit for me" order and StopMarketOrder is a "execute by any mean" order. Depending on a volume sign, positive or negative, they both can open long and short position.

 

 

// current price is $80
// this order says to broker - I agree to buy for any price from 0 to $70
// if price is higher than $70 - do nothing
LimitOrder(symbol, 1, 70.00)

// current price is $60
// this order says to broker - I agree to sell for any price from $70 to infinity
// if price is cheaper than $70 - do nothing
LimitOrder(symbol, -1, 70.00)

// current price is $60
// this order says to broker - when price go to $70 or above
// execute order as fast as possible, even if I have to pay more than $70
StopMarketOrder(symbol, 1, 70.00)

// current price is $80
// this order says to broker - when price go to $70 or below
// execute order as fast as possible, even if I lose money by selling it cheap
StopMarketOrder(symbol, -1, 70.00)

0

Ok, I take my words back. Looks like people at Quant Connect imagine order management differently. Explained here.

0

We modelled StopMarket, StopLimit and Limit orders from Interactive Brokers. 

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.


Drew Baker we'll post an example here tomorrow. The example in the documentation shows a lower price.

// Closing out a long position on market drop
var stopPrice = close * .9975m;
var newTicket = StopMarketOrder("IBM", -100, stopPrice);
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