Hi,
This is my first time building anything, so apologies if the question is a bit basic. I'm trying to get the high and low of the first 30 min of the trading day. When I run my code, I'm expecting it to print the high and low of the 5 days that are within the date ranges I've specified, but I'm not seeing anything in the Logs. Is there anything I'm doing wrong? Thanks
class OpeningRangeBreakout(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 12, 6) # Set Start Date
self.SetEndDate(2021, 12, 10) # Set End Date
self.SetCash(1000) # Set Strategy Cash
self.AddEquity("SPY", Resolution.Minute)
def OnData(self, data):
self.rolling_window = RollingWindow[TradeBar](30) # 30 min lookback
self.first_candles = RollingWindow[TradeBar](30) # First 30 min in a trading day
# Add new candle to rolling window
self.rolling_window.Add(data['SPY'])
if not self.first_candles.IsReady:
self.first_candles.Add(data['SPY'])
# Ensure indicators are ready
if not (self.first_candles.IsReady and self.rolling_window.IsReady):
return
# High/Low of first 30min of trading day
min_first_30min = float("inf")
max_first_30min = 0
for candle in self.first_candles:
if candle.Low < min_first_30min:
min_first_30min = candle.Low
if candle.High > max_first_30min:
max_first_30min = candle.High
# Log values
self.Log(f"Min First 30min: {min_first_30min}")
self.Log(f"Max First 30min: {max_first_30min}\n")
def OnEndOfDay(self):
self.first_candles.Reset()
Vladimir
Ichoz,
Â
Here is "First 30 minutes Highest High and Lowest Low" which plotsÂ
Â
Â
and printsÂ
the first 30 min Highest High and Lowest Low using indicators self.MAX() and self.MIN().
If you are satisfied with my answer, please accept it and don't forget to like it.
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!