Back

StopMarketOrder Fill Price

Hello

I can't follow at which price the StopMarketOrders are filled. The filled price is significantly different what I placed. the LimitOrders are filled at the same price as placed one.
Is it something to do with slippage?

Examples

2018-01-21 19:00:00 __placed StopMarketOrder at: 1.389635000000000000010408341
2018-01-22 19:00:00 Order Executed for: GBPUSD | Time: 1/23/2018 12:00:00 AM OrderID: 5 Symbol: GBPUSD Status: Filled Quantity: 14 FillPrice: 1.39849 USD

2018-01-22 19:00:00 __placed StopMarketOrder at: 1.226130000000000000010408341
2018-01-23 19:00:00 Order Executed for: EURUSD | Time: 1/24/2018 12:00:00 AM OrderID: 11 Symbol: EURUSD Status: Filled Quantity: 16 FillPrice: 1.231 USD

2018-01-25 19:00:00 __placed StopMarketOrder at: 1.415405000000000000010408341
2018-01-26 19:00:00 Order Executed for: GBPUSD | Time: 1/27/2018 12:00:00 AM OrderID: 13 Symbol: GBPUSD Status: Filled Quantity: 14 FillPrice: 1.41688 USD
Update Backtest








Hi I looked at your code and your orders. Your stop market orders were placed 3 days later at 12:00am every time in the code you pasted. I would look at that first. the order should be placed as soon as the trade is placed.

0

also wouldn't you want your stopmarketorder entry price to be below your buy price or above your short price, ? you are saying 

entry_price = price + Decimal(0.0005) , this means your stopmarket(stop loss) is above your entry price.algorithm.StopMarketOrder(target.Symbol, target_quantity, entry_price, tag="where is tag shown?")
0

For Limit orders, when the limit price is reached, the order will be filled at the limit price. For StopMarketOrder, When the stop price is reached, a stop order becomes a market order. The order will be filled at the market price. Forex has quote bar data with bid/ask price. Therefore, the stop market buy orders are filled with ask price and the stop Market sell orders are filled with the bid price.

You can get the bid/ask price with "self.Securities[self.pair].AskPrice" and "self.Securities[self.pair].BidPrice". 
 

def OnOrderEvent(self, orderEvent):
order = self.Transactions.GetOrderById(orderEvent.OrderId)
    if order.Status == OrderStatus.Filled:
        self.Debug("ask "+str(self.Securities[symbol].AskPrice))
        self.Debug("bid "+str(self.Securities[symbol].BidPrice)) 
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.


Hello Jing Wu ,

my logic here is that I want to enter the trade at the stop price that higher than the current price when market price is equal to that stop price. In Oanda platform a stop order is used for this. That's why the confusion.
I thought "When the stop price is reached" means that market price is equal to this stop price.
I will use LimitOrder also for this entry logic. I hope there won't be a problem in live trading.

Independent of this use case I still want to understand the fill price of StopMarketOrders. Is it the Close price of the daily bar (if the resolution is daily) ?
I implemented your suggestion to look at bid and ask. You are right that most of the cases the fill price is equal to this ask price. However, here is a couple of examples where I cannot relate the fill price to ask price but it's equal to stop order price.

2018-08-21 20:00:00 __placed StopMarketOrder at: 1.291015000000000000010408341
2018-08-22 20:00:00 Order Executed for: GBPUSD | Time: 8/23/2018 12:00:00 AM OrderID: 5 Symbol: GBPUSD Status: Filled Quantity: 15 FillPrice: 1.29102 USD
20018-08-22 20:00:00 OnOrder ask: 1.29062
2018-08-22 20:00:00 OnOrder bid: 1.29041
2018-08-22 20:00:00 GBPUSD: Open:1.29052 Close:1.290515

---

2018-09-20 20:00:00 __placed StopMarketOrder at: 1.327570000000000000010408341
2018-09-21 20:00:00 Order Executed for: GBPUSD | Time: 9/22/2018 12:00:00 AM OrderID: 33 Symbol: GBPUSD Status: Filled Quantity: 15 FillPrice: 1.32757 USD
2018-09-21 20:00:00 OnOrder ask: 1.30832
2018-09-21 20:00:00 OnOrder bid: 1.30742
2018-09-21 20:00:00 GBPUSD: Open:1.327065 Close:1.30787

What is the reasoning here?

---
(Apollos Hill hi, it was not a stop 'loss'. I say if market reaches this price, it's a confirmation for me that it would go even higher. Hence, I would buy only at that stop price. I got that I should use LimitOrder for this, Thank you.)

0

backtest attached.

0


If the resolution is daily, the order fills based on the daily bar price. 

For stopMarketOrder, FillPrice = max(StopPrice, marketPrice + slip);

If StopPrice is higher than the current market price + slippage, it will be filled at the stop price.

You can check the fill model of LEAN for StopMarketOrder.

https://github.com/QuantConnect/Lean/blob/72acd7c53cad3dec007dff0d5b0cd5f4679cfcd4/Common/Orders/Fills/FillModel.cs#L122
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