Back

Filled Price of Limit Orders

Hello, I have the following algo that use Bollinger Band Indicator to trigger buy and sell orders.  The algo send buy and sell orders, and then when one of it is filled, send a stopLoss as also check if condition to take profit is achieved.  

The specific problem that Im facing is that on the backtest, there is a sell order because condition to sell is achieved, and the the algo send a limit order with the stop loss with a price of : stopPrice =  stopPrice = round((self.orderTicketShort.AverageFillPrice * 1.1),2). On this order, the stop price is equal to 150.12 and the entry price is 136.469. But the limit order for the stop loss, is executed and filled at a below price than the stopPrice(at date 2019-07-24 on the attached backtest) that is the price of the limit Order. This price is of 139.05.

 self.lossTicketShort = self.LimitOrder(self.ticker,-quantity,stopPrice,'StopLossShort')
 

So I want to know, why if the limit price for exit with loss is 150.12, the order is executed and filled at the price of 139.05.  This problem take place in the first trade of the backtesting 

 

Thanks in advance for your help

Nicolás

 

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

If you change the Debug on line 170 to

self.Debug('entra aca. Stop Price is {} with quantity {}'.format(stopPrice, -quantity))

You'll see that you are placing a buy limit order because the quantity is positive. This limit order has a limit price above the current market price. Limit orders fill once the asset price is equal or better than the limit price.

For a buy order, this means the order will be executed when the stock can be bought at or below the limit price of 150.12. Because the market price of the asset is 139.05, this limit order is immediately filled.

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.


Hello Rahul, thank you for your clear response. I decided to change limit orders to market orders and avoid that situation with the limit orders.

 

 

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