Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Would like some help coding strategy...MACD, RSI, W%R, Stochastic....

Hi there,

I am a former prop trader looking to code and back test a trading strategy...know lots about trading, very little about writing algorithms...

Would anyone like to help/collaborate???

Here are some basic parameters/settings to get started:
Stoch: 10,3,3
RSI: 9
MACD: 12, 26, 9
W%R: 14

Sell long position (if in possession of one) and go short when:

MACD < Signal Line ...and only when conditions of following are met no greater than 7 bars previously RSI >70 and Stoch >80 and W%R>-20

Buy back short position (if in possession of one) and go long when:

MACD > Signal Line ...and only when conditions of following are met no greater than 7 bars previously RSI < 30 and Stoch < 20 (%K & &D) and W%R<-80

All the best,
Bob

12 responses

Revision:
Adjustment to MACD settings: 13, 21, 8

wait a minute, working on it.

Hello Bob,

What do you need help with? The TA-Lib methods recently added to Quantopian might work for you. Have you tried the ta-lib RSI example on the help page?

Grant

Bob, is that if (RSI, Stoch, W%R) conditions are ALL met on the same day ? Or is it just I met one conditions today, another the day before yesterday, and the last one a few days ago and I hit the MACD today, then I go flip my position?

This is my attempt - it only trades 3 or 4 times a year with GOOG. There is probably a lot wrong - I haven't looked at any algorothms for months.

P.

I've tried running minutely with $100,000 from 07/08/2013 to 07/31/2013. This is the start of the log:

2013-07-08 log_order:91 INFO Opening SHORT position by selling 110.0 shares  
2013-07-09 log_order:91 INFO Closing SHORT position by buying 110 shares  
2013-07-09 log_order:91 INFO Opening LONG position by buying 111.0 shares  
2013-07-09 log_order:91 INFO Closing LONG position by selling 111 shares  
2013-07-09 log_order:91 INFO Opening SHORT position by selling 110.0 shares  
2013-07-09 log_order:91 INFO Closing SHORT position by buying 110 shares  
2013-07-09 log_order:91 INFO Opening LONG position by buying 110.0 shares  
2013-07-11 log_order:91 INFO Closing LONG position by selling 110 shares  
2013-07-11 log_order:91 INFO Opening SHORT position by selling 109.0 shares  
2013-07-12 log_order:91 INFO Closing SHORT position by buying 109 shares  
2013-07-12 log_order:91 INFO Opening LONG position by buying 109.0 shares  
2013-07-12 log_order:91 INFO Closing LONG position by selling 109 shares

2013-07-12 log_order:91 INFO Opening SHORT position by selling 108.0 shares

2013-07-12 log_order:91 INFO Closing LONG position by selling 34 shares

2013-07-12 log_order:91 INFO Opening SHORT position by selling 108.0 shares  
2013-07-15 log_order:91 INFO Closing SHORT position by buying 250 shares  
2013-07-15 log_order:91 INFO Opening LONG position by buying 108.0 shares  
2013-07-19 log_order:91 INFO Closing LONG position by selling 108 shares  
2013-07-19 log_order:91 INFO Opening SHORT position by selling 112.0 shares  
2013-07-19 log_order:91 INFO Closing SHORT position by buying 112 shares  

I should not have an 'Opening SHORT' followed by a 'Closing LONG' and the quantities are wrong. Can anyone suggest an explanation?

P.

The answer must involve partial fills like this one today when paper trading the algo. This raises more questions.....GOOG was never near $898.07 today.

P.

Hi Peter, we're looking into the issue you found with $898.07. It might be an over-aggressive default slippage model, since we're still simulating fills until we have the IB backend in place (which is soon, hopefully!).

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.

Thanks, Jean.

I've answered my own question from four posts above. With the default slippage model partial fills occur in consequtive minutes in a minutely backtest which the logic in my algo cannot cope with at present. As a test I have disabled slippage by adding:

set_slippage(slippage.FixedSlippage(spread=0.00))  

P.

Has anyone else coded a version of this? My first attempt (above) has been paper trading for 3 days now:

P.

We finished digging into this yesterday. Specifically, I was looking at Peter's fill of 75 shares at $898.07. My first reaction was the same as Peter's - it looks like an error because it's so high. When I dug into it, I found out that it was as-expected.

What happened here is that a market order of 100 share hit the market at a minute when the total volume that minute was only 300 shares. Our default slippage model was in play, and only 25% of the 300 was permitted to trade (75 shares). The price impact is the default price impact constant (.1) times the volume share squared (25%^2), or .625%. (That's even the exact example in our documentation, not totally by coincidence!). .625% slippage on a close price for that bar of $892.46 gets us to $898.04, plus commission of $.03/share gets us to $898.07.

The next obvious question is, wow, is that slippage model being realistic? Is $5.57 slippage realistic? On one hand, it's not: presumably Google's order book is deep enough that even in a thinly traded minute you wouldn't slip that much. On the other hand, we're only talking about .6% movement of the price, and Google regularly moves up and down by more than twice that in a day.

In the end, the question is going to be how well the backtester holds up to reality. One of the things we're tinkering with right now in live trading is what execution algorithm to use with the brokerage. The leading contender right now is one based on arrival price. Using a method like that would almost always prevent the large price impact that Peter saw. I expect that after we get more experience live trading that we're going to revise our default slippage model. The real-world data will be very informative and helpful.

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.