Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Is this code difficult to write?

Enter a stock 15 minutes prior to market close (such as AAPL) with $20k. (so I would simply be testing a stock of my choosing on a specific day).
Enter a trailing stop of 5%
If trailing stop does not hit, exit position 15 minutes prior to market close on the fifth day.
Cost to enter $5, cost to exit $5.

3 responses

Nope pretty easy.

The trailing stop would take the most effort. To do it correctly, one would need to check price each minute in 'handle_data' and store the highest high for each owned security, then sell if current price is less than trailing stop percent from highest high. Also ensure one doesn't sell twice and account for when to begin entering sell orders. Can a trailing stop order occur while the initial order is partially filled and open or must the initial order be closed? Should an open order be cancelled if that's the case?

I see a lot of posts using a fixed dollar order (ie $20k here). It's better to order 100% of portfolio if one simply wants to test. Otherwise the returns, beta, etc calculated by the backtester will be dependent upon that fixed dollar amount and generally meaningless.

Is this somewhat like you wanted?