Hi Can someone help me make an SMA and EMA of the nasdaq and S&P mini? i'm at a brick wall here..i've explored
and other links but i can't get the code implementation right.
Hi Can someone help me make an SMA and EMA of the nasdaq and S&P mini? i'm at a brick wall here..i've explored
and other links but i can't get the code implementation right.
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.
Hey, this one should help you with the implementation. It's just a case of missing parameters and incorrect syntax.
Thanks for your help. I read over this code and implemented some changes. This is the error i'm getting now.
During the algorithm initialization, the following exception has occurred: Trying to dynamically access a method that does not exist throws a TypeError exception. To prevent the exception, ensure each parameter type matches those required by the EMA method. Please checkout the API documentation.
at Initialize in main.py:line 35
TypeError : No method matches given arguments for EMA
# https://quantpedia.com/Screener/Details/100
from QuantConnect.Data import SubscriptionDataSource
from QuantConnect.Python import PythonData
from QuantConnect.Python import PythonQuandl
from QuantConnect.Data.Custom import *
from sklearn import datasets, linear_model
from datetime import date, timedelta, datetime
from collections import deque
import statsmodels.api as sm
from decimal import Decimal
import numpy as np
class TradeWtiBrentSpreadAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018, 6, 1)
self.SetEndDate(2018, 12, 1)
self.SetCash(1000000)
# import the custom data
self.ES = self.AddFuture(Futures.Indices.SP500EMini, Resolution.Daily)
self.ES.SetFilter(timedelta(0), timedelta(days=180))
#Create the EMA spread for the liquidate signal
self.es1ema = self.EMA(self.ES, 7, Resolution.Daily)
If you check the file I linked, you can see that your syntax is still not correct. self.EMA takes a string as the first parameter, you've given it method.
Hi Douglas, i've tried using a string. when i do self.es1ema = self.EMA("ES", 7, Resolution.Daily) i get this error. i then follow the suggestion of the error by adding the security with
self.AddSecurity(SecurityType.Future, "ES", Resolution.Minute) and that doesn't work
During the algorithm initialization, the following exception has occurred: Exception : Please register to receive data for symbol ' ' using the AddSecurity() function.
at QuantConnect.Algorithm.QCAlgorithm.GetSubscription (QuantConnect.Symbol symbol, System.Nullable`1[T] tickType) [0x00098] in <1d3439f9966d4d178af513edc463b9bd>:0
at QuantConnect.Algorithm.QCAlgorithm.GetSubscription (QuantConnect.Symbol symbol) [0x00001] in <1d3439f9966d4d178af513edc463b9bd>:0
at QuantConnect.Algorithm.QCAlgorithm.CreateIndicatorName (QuantConnect.Symbol symbol, System.String type, System.Nullable`1[T] resolution) [0x00010] in <1d3439f9966d4d178af513edc463b9bd>:0
at QuantConnect.Algorithm.QCAlgorithm.EMA (QuantConnect.Symbol symbol, System.Int32 period, System.Nullable`1[T] resolution, System.Func`2[T,TResult] selector) [0x00013] in <1d3439f9966d4d178af513edc463b9bd>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <2e7c1c96edae44d496118948ca617c11>:0
at Initialize in main.py:line 51
Exception : Please register to receive data for symbol ' ' using the AddSecurity() function.
at QuantConnect.Algorithm.QCAlgorithm.GetSubscription (QuantConnect.Symbol symbol, System.Nullable`1[T] tickType) [0x00098] in <1d3439f9966d4d178af513edc463b9bd>:0
at QuantConnect.Algorithm.QCAlgorithm.GetSubscription (QuantConnect.Symbol symbol) [0x00001] in <1d3439f9966d4d178af513edc463b9bd>:0
at QuantConnect.Algorithm.QCAlgorithm.CreateIndicatorName (QuantConnect.Symbol symbol, System.String type, System.Nullable`1[T] resolution) [0x00010] in <1d3439f9966d4d178af513edc463b9bd>:0
at QuantConnect.Algorithm.QCAlgorithm.EMA (QuantConnect.Symbol symbol, System.Int32 period, System.Nullable`1[T] resolution, System.Func`2[T,TResult] selector) [0x00013] in <1d3439f9966d4d178af513edc463b9bd>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <2e7c1c96edae44d496118948ca617c11>:0
Again, please look at the link I sent you. It's done correctly in there and it would help if you read it line by line to see what's going on.
Hi Douglas,
Thanks for explaining this to me. what am i still doing wrong? I have copied it word for word except i changed the quandl and resolution.
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")
AddReference("QuantConnect.Indicators")
from System import *
from QuantConnect import *
from QuantConnect.Indicators import *
from QuantConnect.Data import *
from QuantConnect.Data.Market import *
from QuantConnect.Algorithm import *
from QuantConnect.Python import PythonData
from QuantConnect.Python import PythonQuandl
from sklearn import datasets, linear_model
from datetime import date, timedelta, datetime
from collections import deque
import statsmodels.api as sm
from decimal import Decimal
import numpy as np
class TradeWtiBrentSpreadAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018, 6, 1)
self.SetEndDate(2018, 12, 1)
self.SetCash(1000000)
# import the custom data
self.AddSecurity(SecurityType.Future, "ES", Resolution.Minute)
self.ESEMA = self.EMA("ES", 14, Resolution.Minute)
I'm still getting the same error.
i finally got it to work.
def Initialize(self):
self.SetStartDate(2018, 6, 1)
self.SetEndDate(2018, 12, 1)
self.SetCash(1000000)
# import the custom data
self.AddData(WTI, "WTI", Resolution.Daily)
self.AddData(BRENT, "BRENT", Resolution.Daily)
self.es = "SCF/CME_ES1_ON"
self.AddData(QuandlFuture, self.es, Resolution.Daily)
self.nq = "SCF/CME_NQ1_ON"
self.AddData(QuandlFuture, self.nq, Resolution.Daily)
self.esema = self.EMA(self.es, 7)
self.nqema = self.EMA(self.nq, 7)
Glad to hear that :)
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.
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!