Hey, I'm trying to trade using velocity/acceleration principles.
I thought a good place to start would be by creating a momentum indicator into another, but for the life of me, I can't seem to do it.
Would anyone give me a hand please?
- I've tried this
- ```
- self.spyVelocity = self.MOMP("SPY", 10, Resolution.Minute)
- self.spyAcceleration = self.MOMP(10, Resolution.Minute)
- self.RegisterIndicator(self.spyVelocity, self.spyAcceleration, Resolution.Minute)
- ```
- as well as this
- ```
- self.spyVelocity = self.MOMP("SPY", 10, Resolution.Minute)
- self.spyAcceleration = IndicatorExtensions.Of(self.MOMP, self.spyVelocity)
- ```
Rahul Chowdhury
Hey Oscar,
We can create a blank MomentumPercent indicator to hold our value for acceleration and then manually update it with values from the velocity. This is easily done using the Updated event handler for our velocity indicator, which fires each time the velocity indicator is updated.
self.spy_velocity = self.MOMP("SPY", 10, Resolution.Minute) self.spy_velocity.Updated += self.OnSPYVelocityself.spy_acceleration = MomentumPercent(10)
Then in our Updated event handler, we can update our acceleration:
def OnSPYVelocity(self, sender, updated): if self.spy_velocity.IsReady: self.spy_acceleration.Update(self.Time, updated.Value)
Best
Rahul
Oscar Lee
Apologies, what does
self.spy_velocity.Updated += self.OnSPYVelocity
do in this context? I'm confused as I understand self.OnSPYVelocity is a function
Rahul Chowdhury
Hey Oscar,
self.spy_velocity.Updated is the Updated event handler method for the indicator.
self.spy_velocity.Updated += self.OnSPYVelocity
This sets the self.OnSPYVelocity method as our Updated event handler, so that self.OnSPYVelocity is called each time self.spy_velocity is updated.
Learn more about event handlers in Python here.
Best
Rahul
Oscar Lee
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!