Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Algo re-buying trailing stop loss idea?

I'm new to Python and I'm just curious. Like is there a way to write an algo that has a small trailing stop loss and that re-buys the stock if the price again goes above the trailing stop loss during that day. You would also have to sell all stock at end of day to prevent price fluctuations when the market is closed. Wouldn't this algo prevent large losses and focuses on the stocks good days. If there is can you tell me please?

1 response

@Jonathan R,

Here's a simple start for you. There's a caveat that you failed to mention which was, how do you get in in the first place before the trailing stop kicks in. Unless you're using a chandelier or TrailingRangeOffset technique as the "trailing stop" mark. Regardless, this strat uses a HighestHigh of N days as the initial entry and if the trailing stop is triggered, then the TrailingStopBounce goes into affect -- for Y days only and at X percent bounce.

Have a look. You can search this forum for code block framework for other entry triggers to add.

The logs will tell you what's going on:

2013-04-01 PRINT >> ThresholdEntry      UNH   @   58.97  
2013-04-05 PRINT << TrailSellStop       CSCO  @   20.60 pnl   0.85  
2013-04-10 PRINT >> ThresholdEntry      INTC  @   22.25  
2013-04-11 PRINT    Bounce triggered    CSCO  @   21.68  >   20.60  
2013-04-11 PRINT >> ThresholdEntry      CSCO  @   21.68