Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Algo for a momentum based strategy

Hi all! I'm new to Quantopian but am fascinated by its potential. I'm using a momentum based strategy for stocks, but don't have a clue on how to start scripting an algo for it. The strat is based on Klein's strat from stockcharts. It has simple rules:

  • Stock has a SCTR > 90
  • Price is above 250 sma
  • SSI (%K) crosses above 20 from below

I have a custom scan in stockcharts, but I'm not sure how to translate that to an algo here. If someone could at least point me in the right direction how to create a scan for these parameters in Quantopian I'd appreciate it. Thanks!

7 responses

Hi Santiago,

Welcome to Quantopian! To scan for these factors, you'll want to use Pipeline, but here's the path I recommend you take:

Python Tutorial: Everything on Quantopian is done in Python! Getting Started Tutorial: This will walk you through the basics of writing an algorithm on Quantopian. Pipeline Tutorial: This will introduce you to Pipeline, which allows you to dynamically select and weights securities based on factors like the ones you described.

I hope this helps.

Disclaimer

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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.

Thank you so much Jamie. I will definitely take a look at these. In your opinion, are the parameters of this strategy even something that could be coded into an algo? I just want to make sure it could be done first before diving into Python.

Could anyone recommend a template that I could start with? It seems like my indictors could be handled well enough in an algo, I'm just not sure how to start it. For the entry/exit I plan to go long at 3:30pm (for stock with a daily gain < 2%) and exit the position after a 2% gain. I think these parameters can also be integrated into the algo without any problem. Just need a template to start with. Thanks!

Attached is a template I use for long only strategies that don't require intra-day data. It can be modified pretty easily for a long/short algorithm.

Everyone has their own style. Look through the the forums here and you'll find a number of good approaches. I like to keep all my data in the dataframe returned by the pipe. It seems confusing at times keeping track of different data structures for what is held, how long, etc. This approach also makes it easy to write the buy and sell rules in a string and then use the pandas 'query" method to select stock based on those rules.

BTW. This isn't much of a strategy. Just put some factors and rules in for demonstration.

Good luck!

Thank you Dan!

Is there a way to code the sctr? It's the stock charts technical rank: Description here

Remember that the SCTR is a RELATIVE score (cross-sectional). You need to calculate the score of several indicators for a particular day for your stock.
Then you do the same for all the 500 stocks in the S&P 500 if that is the index where the stocks belong to.
Each day every stock in the S&P will be ranked from highest to lowest on the terms of this score.
So SCTR is NOT an indicator based on the stock itself - at least it is in the first step. Then you need to compare for that day all the scores and rank them.
That is the way to get values from 100 to 0.
Hope this helps.