I am currently having two problems. The first problem is my algorithm keeps making trades @ 00:00:00. I then changed the order to a MarketOrder, but the same thing happens (It just gets filled at Market Open) I tried writing some code so the Algo can only account for prices during open market and stop pre/post-market trade request.
usa_after_hours = True
#opentime = self.TimeRules.At(9, 30)
#closetime = self.TimeRules.At(15, 59, 45)
#if int(self.time) >= int(opentime) and <= int(closetime):
#usa_after_hours = False
'''I put the int() after i tried it without int()'''
'''I then went on and tried this, which also isnt working'''
if self.IsMarketOpen:
usa_after_hours = False
elif not self.IsMarketOpen:
usa_after_hours = True
if not self.Portfolio.Invested and already_traded and not usa_after_hours:
none of these seem to work and "usa_after_hours" is either stated to be already defined or not defined in the error logs. I saw something about SetMarketHours in an already closed discussion but I couldn't find it the API or documents.
The second problem is I am trying to create a T/F variable that only allows one entry trade in a given period. I named it "already_traded", but that also seems to be not working. So I am assuming that I am not using T/F statements correctly because I have seen QC algorithms use T/F as part of determining to get into a trade or not.
Teddy Brosevelt
I'm not really that good at writing python but I believe this example from Algorithm.Python\BubbleAlgorithm.py answers your question. If not, I do appologize.
"and self.Time.hour > 9 and self.Time.minute > 30:" or "and self.Time.hour < 16 and self.Time.minute < 30:"
# Order stock based on MACD # During market hours, stock is trading, and sufficient cash if self.Securities[stock].Holdings.Quantity == 0 and self._rsiDic[stock].Current.Value < 70 \ and self.Securities[stock].Price != 0 \ and self.Portfolio.Cash > self.Securities[stock].Price * 100 \ and self.Time.hour == 9 and self.Time.minute == 31: self.BuyStock(stock) # Utilize RSI for overbought territories and liquidate that stock if self._rsiDic[stock].Current.Value > 70 and self.Securities[stock].Holdings.Quantity > 0 \ and self.Time.hour == 9 and self.Time.minute == 31: self.SellStock(stock)
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.
Teddy Brosevelt
Actually, you could use it as is and execute your daily buy/sell at 9:31am.
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.
Ez Buckets
Eric Davis, I don't think that fully solves either one of my problems. But I'll keep giving it a look and see what I can do with it. Thank you. But if you have another way that you could code in C# I have no problem looking at it and translating into python.
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.
Teddy Brosevelt
You could also create a trade queue (List) and have the schedule fire every minute, trying to sell everything in the trade queue after the market opens.
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!