Hello,
I have question for the stopMarketOrder. The following is my code in the onData function where it submitted an MaerketOrder and StopMarketOrder together once the entry condition is met. However it looks strange in the backtesting. As you can see from the picture. the MarketOrder and StopMarketOrder filled at the same second, there is more than 0.5 difference for the QQQ data at that specific time point, I am wondering why this can happen? Thanks
public override void OnData(Slice data){
TradeBars bars = data.Bars;
if (entry_cond == true)
{
MarketTicket = MarketOrder(_qqq, -100);
var stopPrice = bars[_qqq].Close + 0.5M;
var newTicket = StopMarketOrder(_qqq, 100, stopPrice);
}
}
Daniel Chen
Hi Hiteck,
Thank you for your question. The time showed in the image is the placement time, not the filled time. Therefore, it is natural that there is a difference in the prices. If you would like to know the exact filled time, please find the filled order to track its status in OnOrderEvent handler:
def OnOrderEvent(self, orderEvent): order = self.Transactions.GetOrderById(orderEvent.OrderId) self.Debug("{0}: {1}: {2}".format(self.Time, order.Type, orderEvent))
For more details, please check out this page. Thank you!
Hiteck
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!