Hi,
consider the following script, it simply buy Futures at 10UTC and sell at 17UTC:
import numpy as np
from System import *
from NodaTime import DateTimeZone
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Data import *
from datetime import timedelta
class ScheduledEventsAlgorithm(QCAlgorithm):
'''Basic template algorithm simply initializes the date range and cash'''
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(2019, 6, 1) #Set Start Date
self.SetEndDate(2020, 6, 1) #Set End Date
self.SetCash(100000) #Set Strategy Cash
#Timezone Setting
self.SetTimeZone(DateTimeZone.Utc)
#
# Setup Interactive Broker
self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage)
#Adding Instruments
self.futureES = self.AddSecurity(SecurityType.Future, Futures.Indices.SP500EMini, Resolution.Hour);
self.futureES.SetFilter(timedelta(0), timedelta(182))
#Logging / Debugs
self.Logging_On = True
self.Debug_On = False
# Set Schedule to buy and sell
self.Schedule.On(self.DateRules.EveryDay(self.futureES.Symbol), self.TimeRules.At(10, 0), self.ESBuy)
self.Schedule.On(self.DateRules.EveryDay(self.futureES.Symbol), self.TimeRules.At(13, 0), self.ESSell)
def OnData(self, data):
# If we haven't already stored the front contract, we need to find it
pass
def ESBuy(self):
if self.Debug_On:
self.Debug("ESBuy: Fired at : {0}".format(self.Time))
self.MarketOrder(self.futureES.Symbol, 1)
def ESSell(self):
if self.Debug_On:
self.Debug("ESSell: Fired at : {0}".format(self.Time))
self.Liquidate
It fails with the following error:
The security with symbol '/ES' is marked as non-tradable.what is the best way to implement such a simple strategy with this asset?
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!