Hi All,
I have been trying to use the ATR indicator value in the RenkoConsolidator for the brick size input. I keep getting error messages including ones that say that ‘Renko consolidator BarSize must be strictly greater than zero’.
Can anyone shed some light on this? Thanks :)
from AlgorithmImports import *
from QuantConnect.DataSource import *
class TrendlineRSI(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2015, 10, 6)
self.SetCash(10000)
self.ticker = self.AddEquity("SPY", Resolution.Minute)
self.rsi = self.RSI(self.ticker.Symbol, 10, Resolution.Minute)
self.lastrsi = {}
self.TREND = self.SMA(self.ticker.Symbol, 30, Resolution.Daily)
self.SetWarmup(43200) # 30 days in minutes
self.atr = self.ATR(self.ticker.Symbol, 14, MovingAverageType.Simple)
self.brick = {}
self.consolidator = RenkoConsolidator(self.brick)
self.consolidator.DataConsolidated += self.OnDataConsolidated
self.SubscriptionManager.AddConsolidator(self.ticker.Symbol, self.consolidator)
def OnData(self, slice):
if self.atr.IsReady:
self.brick[self.ticker.Symbol] = self.atr.Current.Value
self.consolidator.Update(self.brick)
def OnDataConsolidated(self, sender, RenkoBar):
if self.IsWarmingUp:
return
if not self.ticker.Close > self.TREND.Current.Value:
return
if self.ticker.Symbol not in self.lastrsi:
self.lastrsi[self.ticker.Symbol] = self.rsi.Current.Value
if self.lastrsi[self.ticker.Symbol] < 29 and self.rsi.Current.Value > 29:
quantity = self.CalculateOrderQuantity(self.ticker.Symbol, 0.9)
self.MarketOrder(self.ticker.Symbol, quantity)
self.TrailingStopOrder(self.ticker.Symbol, -quantity, 0.007, True)
self.lastrsi[self.ticker.Symbol] = self.rsi.Current.Value
Mia Alissi
Hi James,
The error message you're seeing is likely due to the fact that the ATR (Average True Range) value is not ready when you're trying to use it to set the bar size for the RenkoConsolidator. The ATR indicator requires a certain amount of data before it can provide a valid output. If you try to use it before it's ready, it will return a default value of 0, which is causing the error you're seeing.
To fix this, you should check if the ATR is ready before using its value. You can do this by using the
IsReady
property of the ATR object. Here's how you can modify yourOnData
method to include this check:This will ensure that you only update the RenkoConsolidator's bar size when the ATR has a valid value.
Also, please note that the
Update
method of the RenkoConsolidator expects a data point (like a TradeBar or QuoteBar), not a value. You might need to revise your approach here.I hope this helps! Let me know if you have any other questions.
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.
James hirst
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!