Hello, I am working on a new algorithm using the MACD indicator and it's values, and I have yet in backtests to take any trades, and debugging always gives an MACD value of 0.0. I am using self.var.Current.Value and for the Signal, self.var.Signal.Current.Value, all on minute resolution. I have cloned multiple examples from documentation and elsewhere, still getting no trades and a value of 0.0 when debugging, but I will still post my code just in case.
def Initialize(self):
self.SetStartDate(2021, 1, 1)
self.SetCash(1000000)
self.AddEquity('SPY')
self.SetBenchmark('SPY')
self.SetBrokerageModel(AlphaStreamsBrokerageModel())
self.SetExecution(ImmediateExecutionModel())
self.SetRiskManagement(MaximumDrawdownPercentPerSecurity(0.05))
self.AddSecurity("TQQQ", Resolution.Minute)
self.macA = self.MACD("TQQQ", 12, 26, 9, MovingAverageType.Exponential, Resolution.Minute)
self.SetWarmup(26)
def OnData(self, data):
if self.IsWarmingUp: return
if self.macA.Current.Value < 0:
if self.macA.Signal.Current.Value < self.macA.Current.Value:
self.SetHoldings("TQQQ", .1)
Vladimir
Ethan Wertlieb
Try this
Ethan Wertlieb
Got it, thanks! For any readers in the future the exact change that got it working was changing "AddSecurity" to "AddEquity"
Ethan Wertlieb
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!