Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Trailing stop loss!

does anyone have a ready code for:
a Trailing stop loss that,
after I short it will see 0.30c profit, and start going down 5c each time the stock price goes down.

EXAMPLE:
stock price is 10$ and I short at 10$ the stop loss starts at 10.30$ (30c stop loss of the shorting price)
stock goes down to 9.70$ (0,30c profit).
stop loss goes to 9.75$
stock goes down to 9.65$
stop loss goes to 9.70$
stock goes down to 9.60$
stop loss goes down to 9.65$
etc...

Is it hard to make it? does anyone have one ready to share? something simmilar ?

Thanks ALOT!

1 response

Hi Roman - I found this simple code from someone else in the Quantopian community that works well. It will return a price amount that doesn't decrease which you can build trading logic around. You should be able to adapt it to your needs.

def set_trailing_stop(context,data):  
      price = data[context.stock].price  
      context.stop_price = max(context.stop_price, context.stop_pct * price)  
      return context.stop_price  

Hope this helps!
-Stefan