Hello,
Im absolutely new to qc. However Im trying to make an algorithm that buys whenever the RSI is less than 28 and sells whenever its above 70. The issue is, that it never buys anything and it seems that the data is not even refreshin.
Im really frustrated, what am I doing wrong?
class rsi_loop(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 10, 10) #Set Start Date
self.SetEndDate(2021,10,18)
self.SetCash(100)
self.invested = 10
# Set deposits
#self.Schedule.On(self.DateRules.Every(DayOfWeek.Monday),self.TimeRules.At(12,00),self.OnData)
# Set Brokerage Model
#self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash)
self.AddCrypto("BTCUSD", Resolution.Tick)
self.btcusd = self.AddCrypto("BTCUSD", Resolution.Minute)
RSI_period = 14
self.RSI_ind_BTC = self.RSI(self.btcusd.Symbol,RSI_period,Resolution.Minute)
self.SetWarmUp(RSI_period)
self.allowed_operations = 8
self.quantity = (self.Portfolio.Cash / self.allowed_operations)
self.portions = (self.Portfolio.Cash / self.allowed_operations) / self.Portfolio.Cash
#initializing variables
self.btc_longoper = True
# Create our rolling windows
#self.tradeBarWindow = RollingWindow[TradeBar](5) # Store the last 5 values
#self.rsiWindow = RollingWindow[Decimal](10) # Store the last 10 values
def OnData(self, data):
if not self.RSI_ind_BTC.IsReady:
return
if not self.Portfolio.Invested and self.RSI_ind_BTC.Current.Value < 28 and self.btc_longoper == True:
quantity = self.CalculateOrderQuantity(self.btcusd.Symbol, 0.5)
self.MarketOrder(self.btcusd.Symbol,quantity)
#self.SetHoldings(self.btcusd.Symbol,0.5)
self.Debug("RSI < 30, Buying")
self.btc_longoper = False
if self.btc_longoper == False and self.RSI_ind_BTC.Current.Value > 70:
self.Liquidate()
self.Plot("Indicators","RSI", self.RSI_ind_BTC.Current.Value)
Vladimir
Álvaro Anton Blanco.
Is this what you are looking for?
Álvaro Anton Blanco
Hello Vladimir,
first of all, thank you very much for replying! This is awesome, thank you. Howevery Ive got some questions
Why would you set up a cash account with 1 million Dollar Balance? Thats what I dont understand, the thing is, that when it goes live, no one would ever invest such high quantities…
Vladimir
Álvaro Anton Blanco.
Here is a version with self.SetCash(1000).
If you are satisfied with my answer, please accept it.
Álvaro Anton Blanco
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!