Hi,
I am trying to get the 21 day EMA of TQQ as such:
class MyClass(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 8, 15) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.tqqq = self.AddEquity("TQQQ", Resolution.Daily)
# create 21 day EMA of TQQQ
self.ema = ExponentialMovingAverage("TQQQ", 21);
def OnData(self, data):
self.Debug("ema: " + str(self.ema))
However, in the log - the EMA is always 0.0.
Could someone please point out what I am doing wrong with EMA?
Fred Painchaud
Hi Etay,
You are not registering your EMA and you are using the manual method so you must register.
For simplicity at the stage you are in your algo, try using this:
self.ema = self.EMA("TQQQ", 21, Resolution.Daily);
and in OnData:
self.Debug("ema: " + str(self.ema.Current.Value))
Fred
Tashfeen Ekram
I tried that and it did not solve it for me.
The resoltion I define in Initialize is minute but I am looking compare current price on a minute to minute basis relative to 20 EMA daily price. Is that possible?
Ashutosh
Hi Tashfeen Ekram
There are multiple ways to address your problem statement.
The straightforward way is to initialize stock with minute data and indicator with daily data.
Hope this gives you some direction!
Reference output:
Backtest Attached.
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.
Etay Luz
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!