| Overall Statistics |
|
Total Trades 1 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 $1.85 Estimated Strategy Capacity $50000000.00 Lowest Capacity Asset NQ XKGCMV4QK9VL |
#region imports
from AlgorithmImports import *
#endregion
class SimpleNQExample(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 12, 1) # Set Start Date
self.SetEndDate(2020, 12, 1)
self.SetCash(100000) # Set Strategy Cash
self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin)
self.SetTimeZone("America/New_York")
# Set up the future we're looking at
future = Futures.Indices.NASDAQ100EMini
self._continuousContract = self.AddFuture(future,
dataNormalizationMode = DataNormalizationMode.BackwardsRatio,
dataMappingMode = DataMappingMode.OpenInterest,
contractDepthOffset = 0)
self.commod = self._continuousContract.Symbol
# We'll set up a couple of simple example consolidators
# First, an ATR on the 5m
self._5mATR = ParabolicStopAndReverse(0.02, 0.02, 0.2)
# Next, a 9 SMA on the 3m
self._3m20pSMA = SimpleMovingAverage("5m9pSMA", 9)
# Now the handlers for those consolidators
self.MyConsHandler = []
self.MyConsHandler.append(self.Consolidate(self.commod, timedelta(minutes=4), self._5BarHandler))
self.MyConsHandler.append(self.Consolidate(self.commod, timedelta(minutes=5), self._3BarHandler))
count = 0
# Our longest consolidator will need 9*3 minutes to warm up, so we'll grab that much history
longest = 9*3
history = self.History(self.commod, longest, Resolution.Minute)
for index, row in history.iterrows():
# self.Log(index)
bar = TradeBar(index[2]-Time.OneMinute, self.commod, row.open, row.high, row.low, row.close, row.volume)
# self.Log(bar)
count += 1
# Allow the consolidators to update
for consolidator in self.MyConsHandler:
consolidator.Update(bar)
self.Log("counter for history: {0}".format(count))
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
'''
if not self.Portfolio.Invested:
self.Log("Buying {0}".format( self.commod))
# .Mapped is required to get the continuous contract's current contract
self.MarketOrder(self._continuousContract.Mapped, 1, False, "test")
def _3BarHandler(self, consolidatedBar):
self.Log("Updating the 3m Consolidators")
# SMA takes a data point, which is a time and a price
self._3m20pSMA.Update(consolidatedBar.EndTime, consolidatedBar.Close)
def _5BarHandler(self, consolidatedBar):
self.Log("Updating the 5m Consolidators")
# ATR takse a bar, so we can just give it consolidatedBar
self._5mATR.Update(consolidatedBar)