Back

Stock universe filter with moving average

Suppose I want to create a stock universe (based on daily price bars) filtered to include only those stocks that meet these two conditions:

1. Open price today gaps up from yesterday's close by more than X%

2. Price today and yesterday are both above the 50 day simple moving average.

Is there any way to filter stocks based on where the price is with respect to a moving average? What about filtering on other indicators like RSI or stochastics? 

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 Marc, take a look at the docs here. Filtering the universe by a technical indicator is possible using the SelectionData class. It is a tidy way to group together variables for our universe selection and update any indicators all in a few lines of code. In the documentation there are multiple examples.

In order to include yesterdays price in the comparison, it looks like you will have to request historical data. One idea could be requesting the historical price and saving it in the SelectionData class as well, and then comparing the values in the Coarse Universe Selection.

0

Is there a good C# example of this in Lean? Anytime I try to run something like from the example in live or paper trading I get the "10 minute timeout" in the morning.

0

Hi Sean,

Can you attach a backtest or provide a link to the demo algorithm that you are running? This will help us pinpoint the source of the issue.

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.


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