Back

Help: How to pipe a momentum indicator into another momentum indicator?

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?


 
  1.  
  2. I've tried this
  3.  
  4. ```
  5. self.spyVelocity = self.MOMP("SPY", 10, Resolution.Minute)
  6.  
  7. self.spyAcceleration = self.MOMP(10, Resolution.Minute)
  8. self.RegisterIndicator(self.spyVelocity, self.spyAcceleration, Resolution.Minute)
  9. ```
  10.  
  11. as well as this
  12.  
  13. ```
  14. self.spyVelocity = self.MOMP("SPY", 10, Resolution.Minute)
  15. self.spyAcceleration = IndicatorExtensions.Of(self.MOMP, self.spyVelocity)
  16. ```
Update Backtest







0

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 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

1

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.


Apologies, what does

self.spy_velocity.Updated += self.OnSPYVelocity

do in this context? I'm confused as I understand self.OnSPYVelocity is a function

0

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

1

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.


Update Backtest





0

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.


Loading...

This discussion is closed