Hi folks,
I am trying to work with Consolidated bars and I can't seem to get the event handler to fire.
Ideally I want to work with 5 minute bars and have this 5 minute data populate my indicators. I think I have my head around how to do that via initiating the indicator like so in the Initialize function.
self.psar = ParabolicStopAndReverse('psar',0.02, 0.02, 0.12)
self.psar.Updated += self.psarUpdated
self.RegisterIndicator(self.symbol.Symbol, self.psar, timedelta(minutes=5))
# Also want to keep a history of the PSAR Values
self.rwRL10 = RollingWindow[IndicatorDataPoint](self.p['istop_lookback'])
And then I update the rolling window like so:
def psarUpdated(self, sender, updated):
if self.psar.IsReady:
self.rwPsar.Add(self.psar.Current.Value)
But at the moment I cant even get the 5 minute bars to print, I actually can't get any of the consolidators to print. I've tried a few different methods, but I feel like I am missing something stupid.
My logs from the backtest:
1
|
12:17:25
:
Building Project ID: 11295116 Content Signature: eb4a969e7bf0f6694774fa5db1816931
2
|
12:17:25
:
Backtesting Project...
3
|
12:17:25
:
Build Request Successful for Project ID: 11295116 CompileID: 8ddc4445b68f0bef5142b650682b3656-eb4a969e7bf0f6694774fa5db1816931 Lean Version: 2.5.0.0.13797
4
|
12:17:44
:
Successfully sent backtest request for 'Hyper-Active Orange Badger', (Backtest Id: 7da9965baec5a45ba445735f5d19a443)
5
|
12:17:49
:
Initializing algorithm...
6
|
12:17:50
:
Launching analysis for 7da9965baec5a45ba445735f5d19a443 with LEAN Engine v2.5.0.0.13797
7
|
12:17:50
:
2022-04-14 00:00:00 >> Setup Symbol >> AUDUSD
8
|
12:17:50
:
Algorithm (7da9965baec5a45ba445735f5d19a443) Completed.
9
|
12:17:50
:
Algorithm Id:(7da9965baec5a45ba445735f5d19a443) completed in 0.30 seconds at 0k data points per second. Processing total of 22 data points.
10
|
12:17:50
:
Backtest deployed in 6.158 seconds
11
|
12:17:51
:
Backtest Cloud Upload completed ID: 7da9965baec5a45ba445735f5d19a443
And from the logging console:
2022-04-14 00:00:00 : Launching analysis for 7da9965baec5a45ba445735f5d19a443 with LEAN Engine v2.5.0.0.13797
2022-04-14 00:00:00 : 2022-04-14 00:00:00 >> Setup Symbol >> AUDUSD
2022-04-15 06:00:00 : Algorithm Id:(7da9965baec5a45ba445735f5d19a443) completed in 0.30 seconds at 0k data points per second. Processing total of 22 data points.
My code:
class EnergeticSkyBlueBuffalo(QCAlgorithm):
def Initialize(self):
# In initialize method:
self.SetTimeZone("Australia/Brisbane")
self.SetStartDate(2022, 4, 14) # Set Start Date
self.SetEndDate(2022, 4, 15)
self.SetCash(50000) # Set Strategy Cash
self.symbol = self.AddForex("AUDUSD",Resolution.Minute, Market.FXCM)
self.Debug(f"{self.Time} >> Setup Symbol >> {self.symbol.Symbol}")
self.minuteConsolidator = QuoteBarConsolidator(timedelta(minutes=5))
self.minuteConsolidator.DataConsolidated += self.barSizeMinuteHandler
self.SubscriptionManager.AddConsolidator(self.symbol.Symbol, self.minuteConsolidator)
thirtyMinuteConsolidator =QuoteBarConsolidator(timedelta(minutes=30))
thirtyMinuteConsolidator.DataConsolidated += self.ThirtyMinuteBarHandler
self.SubscriptionManager.AddConsolidator(self.symbol.Symbol, thirtyMinuteConsolidator)
self.Consolidate(self.symbol.Symbol, Resolution.Minute, self.MinuteAUDUSDHandler)
def OnData(self, data: Slice):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
Arguments:
data: Slice object keyed by symbol containing the stock data
'''
self.Debug(f"OnData: >> {data.Close}")
self.Log("Additional detailed logging messages")
def barSizeMinuteHandler(self, sender, consolidatedBar):
self.Debug(f"{consolidatedBar.EndTime} >> barSizeMinuteHandler >> {consolidatedBar.Close}")
self.Log(f"{consolidatedBar.EndTime} >> barSizeMinuteHandler >> {consolidatedBar.Close}")
def ThirtyMinuteBarHandler(self, sender, bar):
self.Debug(str(self.Time) + " " + str(bar))
def MinuteAUDUSDHandler(self, consolidated):
'''This is our event handler for our daily consolidated defined using the Consolidate method'''
self.Log(f"{consolidated.EndTime} AUDUSD Daily consolidated.")
Vladimir
John M
“Forex any minutes bar size resolution chart” might help.
If you are satisfied with my answer, please accept it and don't forget to like it.
John M
Interesting if I change the Market to Oanda the bars printed
self.symbol = self.AddForex("AUDUSD",Resolution.Minute, Market.Oanda)
Fred Painchaud
Hi John,
FXCM has been abandoned by QC in May 2021. The Data Explorer is unfortunately not up to date 100%.
So the issue with your first algo is that you get no data at all. Sorry since I feel you spent some time trying to debug that 😊.
Keep this in mind: you had those calls in OnData:
but did not see any of those logs in the algo logs. Thus, one possible reason: OnData is not being called. And the only reason for OnData not being called is that you have no data.
Fred
John M
Thanks Fred Painchaud , that explains why the data handler was not being fired. Changing it too Oanda, or removing it all together resolves the issue and data starts to flow.
Spent way to long trying to figure that out :facepalm
John M
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!