Back

Taking the Opening range and applying it to a future symbol- stuck

class OpenRangeBreakout(QCAlgorithm):

openingBar = None
currentBar = None

def Initialize(self):
self.SetStartDate(2018, 7, 10) # Set Start Date
self.SetEndDate(2019, 6, 30) # Set End Date
self.SetCash(100000) # Set Strategy Cash

# Subscribe to TSLA with Minute Resolution
future = self.AddFuture(Futures.Indices.SP500EMini)
#1. Create our consolidator with a timedelta of 30 min


self.Consolidate("SP500EMini", timedelta(minutes=30),self.OnDataConsolidated)
def OnData(self, data):
if self.Portfolio.Invested or self.openingBar is None:
return
if data['SP500EMini'].Close > self.openingBar.High:
self.SetHoldings("SP500EMini",1)
elif data["SP500EMini"].Close < self.openingBar.Low:
self.SetHoldings("SP500EMini",-1)

#2. Create a function OnDataConsolidator which saves the currentBar as bar
def OnDataConsolidated(self, bar):
#1. Check the time, we only want to work with the first 30min after Market Open
if bar.Time.hour == 9 and bar.Time.minute == 30:
#2. Save one bar as openingBar
self.openingBar = bar

I am trying to take the "Boot camp" tutorial and apply them to futures. And I keep getting stuck. What am I doing wrong? Any help is greatly appreciated. 

Update Backtest







0

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.


Hi Joshua,

Thanks for sharing your algorithm! Good work building off the Boot Camp lesson.

In this case we do not have enough cash ($100,000). If we increase our cash to $1,000,000 we will see trades. We are using a manual consolidator in this example.

Here is a revision of your algorithm: 

class BasicTemplateFuturesConsolidationAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018, 7, 10) # Set Start Date
self.SetEndDate(2019, 6, 30) # Set End Date
self.SetCash(1000000) # Set Strategy Cash
# Subscribe and set our expiry filter for the futures chain
future = self.AddFuture(Futures.Indices.SP500EMini)
future.SetFilter(timedelta(0), timedelta(182))
self.consolidators = dict()

def OnDataConsolidated(self, bar):
symbol = bar.Symbol
price = self.Securities[symbol].Close
if price >= bar.High:
self.SetHoldings(symbol, 1)
if price <= bar.Low:
self.SetHoldings(symbol,-1)

def OnSecuritiesChanged(self, changes):
for security in changes.AddedSecurities:
symbol = security.Symbol
consolidator = self.Consolidate(symbol, timedelta(minutes=30), self.OnDataConsolidated)
self.consolidators[symbol] = consolidator

for security in changes.RemovedSecurities:
symbol = security.Symbol
consolidator = self.consolidators.pop(symbol)
self.SubscriptionManager.RemoveConsolidator(symbol, consolidator)
consolidator.DataConsolidated -= self.OnDataConsolidated
if security.Invested:
self.Liquidate(symbol, 'Remove from Futures Chains')

 

Also note that we need to remove securities that leave our universe. 

Hope this is helpful!

Sherry

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed