How to implement a ratio price, and put that into an indicator

Back

Need some indicator help.

I want to take a ratio of two prices, say (SPY.price / TLT.price), then put that value into an indicator like RSI or SMA. So I have this code, but I must not be putting it in the right places.

I put this "self.ratio = self.Securities["SPY"].Price/self.Securities["TLT"].Price" in OnData.

And put this in Initialize "self.sma = self.SMA("self.ratio", 30, Resolution.Daily)"

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.


Hi Mark,

You won't be able to have the indicator do the automatic update with a custom data point (meaning a data point not in a trade or quote bar).

The method you are using is a helper method, SMA, on the QCAlgorithm class.  Instead of using it you will need to create an instance of the SimpleMovingAverage class and then update it in your OnData method.

self.sma = SimpleMovingAverage(30)

then in OnData

self.sma.Update(self.Time, ratio)

If you want this to be daily and you are running on minute timeframes you will need an if statement to only update the sma once.  The best option would be to create a daily consolidator and do the sma update in the OnConsolidated event.

I would recommend you look through the bootcamp as these concepts are explained there.

0

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

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!