Hi,
I create 15 min SPX Index consolidation and based on this data try to buy SP500EMini.
My code not process marketorder for future. How I can by SP500EMini from OnDataConsolidated15min?
Thanks for help.
def OnDataConsolidated15min(self, sender, TradeBar):
self.rsi94.Update(TradeBar.EndTime,TradeBar.Close)
rsi94_current = self.rsi94.Current.Value
self.rsi94_Window.Add(self.rsi94.Current)
if self.rsi94_Window.Count >=2:
rsi94c = self.rsi94.Current.Value
rsi94p = self.rsi94_Window[1].Value
self.atr.Update(TradeBar)
atr = self.atr.Current.Value
position = self.Portfolio[self.future_symbol].Quantity
if position == 0:
if rsi94c > 50 and rsi94p < 50 and rsi94c != 0 and rsi94p != 0:
cash = self.Portfolio.Cash
last_price = self.Securities[self.future_symbol].Price
ticket = self.MarketOrder(self.future_symbol, 100)
self.Debug(f"Quantity filled: {ticket.QuantityFilled}; Fill price: {ticket.AverageFillPrice}")
buy_price = ticket.AverageFillPrice
self.stop_price = buy_price + self.atr.Current.Value * 0.5
self.limit_price = buy_price - self.atr.Current.Value * 20
self.stopMarketTicket = self.StopMarketOrder(self.future_symbol, 100, self.stop_price)
self.limitTicket = self.LimitOrder(self.future_symbol, 100, self.limit_price)
Louis Szeto
Hi Vytautas
The code snippets until the market order look fine to me. However, future is not a very liquid asset to trade and thus the order might not be filled immediately. Put the take-profit/stop-loss logic into the OnOrderEvent handler after the order was filled. Also, it is recommended to add a property of the valid time of the submitted order to avoid too-delayed filling.
Best
Louis
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.
Vytautas Zukauskas
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!