| 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 -3.215 Tracking Error 0.109 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
from QuantConnect.Data.Market import TradeBar
### <summary>
### Using rolling windows for efficient storage of historical data; which automatically clears after a period of time.
### </summary>
### <meta name="tag" content="using data" />
### <meta name="tag" content="history and warm up" />
### <meta name="tag" content="history" />
### <meta name="tag" content="warm up" />
### <meta name="tag" content="indicators" />
### <meta name="tag" content="rolling windows" />
class RollingWindowAlgorithm(QCAlgorithm):
def Initialize(self):
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
self.SetStartDate(2021,11,1) #Set Start Date
self.SetEndDate(datetime.now()) #Set End Date
self.SetCash(25000) #Set Strategy Cash
# Find more symbols here: http://quantconnect.com/data
self.AddEquity("QQQ", Resolution.Minute)
# Creates a Rolling Window indicator to keep the 2 TradeBar
self.windowqqq = RollingWindow[TradeBar](2) # For other security types, use QuoteBar
self.qqqrsi = RelativeStrengthIndex("QQQ", 14)
#add tqqqrsisma indicator in a rolling window
self.qqqrsisma = IndicatorExtensions.SMA(self.qqqrsi, 14)
self.qqqrsisma.Updated += self.qqqrsismaUpdated
self.qqqrsismarw = RollingWindow[IndicatorDataPoint](14)
# create the 15-minutes data consolidator
thirtyMinuteConsolidator = TradeBarConsolidator(timedelta(minutes=30))
thirtyMinuteConsolidator.DataConsolidated += self.thirtyMinuteBarHandler
# register the 15-minute consolidated bar data to automatically update the indicator
self.RegisterIndicator("QQQ", self.qqqrsisma, thirtyMinuteConsolidator)
self.SubscriptionManager.AddConsolidator("QQQ", thirtyMinuteConsolidator)
#Sets the benchmark, brokerage model and warm up time
self.SetBenchmark("QQQ")
self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage)
self.SetWarmUp(60)
def qqqrsismaUpdated(self, sender, updated):
'''Adds updated values to rolling window'''
self.qqqrsismarw.Add(updated)
def OnData(self, data):
pass
def thirtyMinuteBarHandler(self, sender, consolidated):
# Wait for windows to be ready.
if not (self.qqqrsismarw.IsReady): return
currqqqrsisma = self.qqqrsismarw[0] # Current SMA had index zero.
pastqqqrsisma = self.qqqrsismarw[1] # Previous sma
qqqrsislope = currqqqrsisma.Value - pastqqqrsisma.Value
self.Log("currqqqrsisma: {0} pastqqqrsisma: {1} qqqrsislope: {2}".format(currqqqrsisma, pastqqqrsisma, qqqrsislope))