Hi,
- I have created an algorithm using tick resolution
- I consolidated the ticks into minute candles
- I created a rolling window of 3 with the consolidated candles (i.e. 3 x 1 min candles)
- I want to access the high/low of the rolling window
Code is as below - for some reason it won't let me attach backtest
# region imports
from AlgorithmImports import *
# endregion
# ------------------------------------------------------------
TICKER = "SPY"; OPENING_RANGE = 3; WAIT = 0; MULTIPLIER = 1
# ------------------------------------------------------------
class MeasuredMagentaDogfish(QCAlgorithm):
def Initialize(self):
self.SetSecurityInitializer(lambda x: x.SetDataNormalizationMode(DataNormalizationMode.Raw))
self.SetStartDate(2023, 3, 9) # Set Start Date
self.SetCash(10000) # Set Strategy Cash
self.stock = self.AddEquity(TICKER, Resolution.Tick).Symbol
self.high_window = RollingWindow[float](3)
self.low_window = RollingWindow[float](3)
self.min_value = 0
self.max_value = 0
consolidator = TickQuoteBarConsolidator(TimeSpan.FromMinutes(1)) ## force consolidator to produce 1 minute bars
consolidator.DataConsolidated += self.OnCandle
self.SubscriptionManager.AddConsolidator(self.stock, consolidator)
def OnData(self, data):
## Any trading code in here will be at the tick level
pass
def OnCandle(self, sender, bar):
## Any trading code in here will be at the minute level
self.high_window.Add(bar.High)
self.low_window.Add(bar.Low)
if self.high_window.IsReady and self.low_window.IsReady:
self.max_value = max(list(self.high_window[0:2]))
self.min_value = min(list(self.low_window[0:2]))
self.Log("High: " + str(self.max_value))
self.Log("Low: " + str(self.min_value))
I keep getting the below error - what am I doing wrong?
Trying to dynamically access a method that does not exist throws a TypeError exception. To prevent the exception, ensure each parameter type matches those required by the 'slice'>) method. Please checkout the API documentation.
at OnCandle
self.max_value = max(list(self.high_window[0:2]))
at Python.Runtime.PythonException.ThrowLastAsClrException()
at Python.Runtime.PyObject.Invoke(PyTuple args in main.py: line 34
Nico Xenox
Hey mcdawgzy,
this one was a tricky problem. Instead of writing the selection of rolling windows like this:
you have to write it like this:
Hope it helps ;)
Best,
Nico
Mcdawgzy
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!