Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
# region imports from AlgorithmImports import * # endregion class CryingYellowJaguar(QCAlgorithm): def Initialize(self): self.SetStartDate(2022, 7, 3) # Set Start Date self.SetEndDate(2022, 7, 4) self.SetCash(100000) # Set Strategy Cash #pair = "US30USD" self.pair = self.AddCfd("US30USD", Resolution.Second, Market.Oanda).Symbol #Custom Weekly Consolidator w = QuoteBarConsolidator(self.CustomWeeklyConsolidator) w.DataConsolidated += self.OnDataCustomWeekly #History Call #Re the following call, if, say, you call it on June 26th, it will give you all day bars from June 5th to June 26th. #That does not mean you will get 21 day bars as a result... You won't get bars on Saturdays, for instance #Just so you know. history = self.History(self.pair, timedelta(21), Resolution.Daily) #history call for three weeks for index, row in history.iterrows(): #create bars from returned dataframe quote_bar = QuoteBar(index[1] - timedelta(1), self.pair, Bar(row.bidopen, row.bidhigh, row.bidlow, row.bidclose), 0.0, Bar(row.askopen, row.askhigh, row.asklow, row.askclose), 0.0, timedelta(1)) self.Log(quote_bar.EndTime) w.Update(quote_bar) def OnData(self, data): pass def OnDataCustomWeekly(self, sender, dataCustomDayStart): self.Log("Weekly Hello") self.Log(f'O: {dataCustomWeekly.Open} H: {dataCustomWeekly.High} L: {dataCustomWeekly.Low} C: {dataCustomWeekly.Close}') def CustomWeeklyConsolidator(self, dt: datetime) -> CalendarInfo: #Custom Weekly On Futures / Forex Time 17h start #From https://www.quantconnect.com/docs/v2/writing-algorithms/consolidating-data/consolidator-types#02-Time-Period-Consolidators #This code seeks to consolidate data between Sundays at 17:00:00:0.0 #So a week is considered between Sunday 17:00:00:0.0 (inclusive) and the next Sunday 17:00:00:0.0 (exclusive - the last tick I mean) #Just so you know again. #For your use case, it seems ok. #But you can have incomplete weeks, of course. If the data starts on a Wednesday, say, that Wednesday, plus Thursday-Friday and Sunday until 17h00 #is going to go in the first weekly bar. Then, it IS a weekly bar, but backed with less data than the full week. period = timedelta(7) dt = dt.replace(hour=17, minute=0, second=0, microsecond=0) delta = 1+dt.weekday() if delta > 6: delta = 0 start = dt-timedelta(delta) return CalendarInfo(start, period)
# region imports from AlgorithmImports import * # endregion class CryingYellowJaguar(QCAlgorithm): def Initialize(self): self.SetStartDate(2022, 7, 3) # Set Start Date self.SetEndDate(2022, 7, 4) self.SetCash(100000) # Set Strategy Cash #pair = "US30USD" self.pair = self.AddCfd("US30USD", Resolution.Second, Market.Oanda).Symbol #Custom Weekly Consolidator w = QuoteBarConsolidator(self.CustomWeeklyConsolidator) w.DataConsolidated += self.OnDataCustomWeekly #History Call #timedelta is 21 calendar days, otherwise is 21 daily bars #problem was arising from not using timedelta ###Re the following call, if, say, you call it on June 26th, it will give you all day bars from June 5th to June 26th. #That does not mean you will get 21 day bars as a result... You won't get bars on Saturdays, for instance #Just so you know. history = self.History(self.pair, timedelta(days=21), Resolution.Hour) #history call for three weeks for index, row in history.iterrows(): #create bars from returned dataframe quote_bar = QuoteBar(index[1] - timedelta(1), self.pair, Bar(row.bidopen, row.bidhigh, row.bidlow, row.bidclose), 0.0, Bar(row.askopen, row.askhigh, row.asklow, row.askclose), 0.0, timedelta(1)) #self.Log(quote_bar.EndTime) w.Update(quote_bar) def OnData(self, data): pass def OnDataCustomWeekly(self, sender, dataCustomWeekly): self.Log("Weekly Hello") self.Log(f'O: {dataCustomWeekly.Open} H: {dataCustomWeekly.High} L: {dataCustomWeekly.Low} C: {dataCustomWeekly.Close}') def CustomWeeklyConsolidator(self, dt: datetime) -> CalendarInfo: #Custom Weekly On Futures / Forex Time 17h start #From https://www.quantconnect.com/docs/v2/writing-algorithms/consolidating-data/consolidator-types#02-Time-Period-Consolidators #This code seeks to consolidate data between Sundays at 17:00:00:0.0 #So a week is considered between Sunday 17:00:00:0.0 (inclusive) and the next Sunday 17:00:00:0.0 (exclusive - the last tick I mean) #Just so you know again. #For your use case, it seems ok. #But you can have incomplete weeks, of course. If the data starts on a Wednesday, say, that Wednesday, plus Thursday-Friday and Sunday until 17h00 #is going to go in the first weekly bar. Then, it IS a weekly bar, but backed with less data than the full week. period = timedelta(7) dt = dt.replace(hour=17, minute=0, second=0, microsecond=0) delta = 1+dt.weekday() if delta > 6: delta = 0 start = dt-timedelta(delta) return CalendarInfo(start, period)