Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Trying to day trade a gap up strategy. Please help!

Hey guys, thanks in advance. Trying to trade this strategy I've got in mind but I can get the the orders in yet. I've got my pipeline set up but struggling on how to select only gap ups > 8% to trade. Its not filtering anything out on my open function like it should. My open function should run at 8:31. It should screen 8% or more gap ups and then place a trade for each one of those that opened up. Any help?

4 responses

One problem I have is that I'm so new that I just dont understand whats going on lines 99-111 here to change it. Specifically, I dont understand the "as_matrix" or the bracketed part after the "as_matrix". Can anyone explain how I can visualize, like maybe in a chart, the opens, closes and gaps part so that I can adjust 102-111 to get a small set (~10) of stocks that have gaped up 8% or more for the day?

@ David

The 'as_matrix' method simply turns the output of the 'data.history' method from a Pandas dataframe to a Numpy array (not a matrix which is a bit misleading). See http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.as_matrix.html. Anyway, I'm not sure why this is needed. It would seem to be easier to just leave it as a pandas dataframe.

The bigger picture is this code is way bloated for what you are trying to accomplish. No wonder you may not understand it. Would you be open to starting fresh from a simpler version? I could maybe help.

One question. When you say "stocks that have gaped up 8% or more for the day" what exactly do you mean? It appears in your algorithm that you get 31 days worth of data but only use the current day. Is that correct? Do you want the gap to be the difference between high and low for the current day, or from the previous day (remember if you trade at market open there will only be 1 minute of data to get highs and lows).

Thanks for your reply. I took those lines of code for the gap up calculation from a "multi stock gap up strategy" post on here. He used 31 days because he was filtering other stocks out by different conditions that looked back the last month. I'm not doing that. I just want to isolate stocks that are up 8% or more at the open of the current day compared to the close of the previous day. I realize I will not obtain that data until the close of the first minute (8:31) which is fine. at 8:31 I then want to be able to use the ordering code from lines 114-122 to place orders on the few stocks left in the list.

@David

Take a look at the attached algorithm. I think it buys what you want but wasn't sure how you wanted to determine what/when to sell. The biggest change is to get rid of the 'for loops' as much as possible and let Pandas do that for you. Also, it puts the current price into the pipeline output dataframe. That makes querys and comparisons more consistent.

This is just one of a zillion ways to code this. Everyone has their preferences, but thought this might be a little simpler starting point.