Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Stop Order and TA-LIB Questions

Hello Quantopian,

Question 1:
I would like to know if there is currently, or on the to-do list, a way to place moving stop-loss orders. Say I place an order with a stop at 10% below the order price, if the price goes up I would want that 10% to follow the price rise and lock in some gains. Maybe something to the effect of

order(Sid, n, stop_price=lambda price: .9*price if price > current_price else .9*current_price)  

I don't know how feasible something like this would be, but it sure would be nice.

Question 2:
When using TA-Lib functions with minute data is the function basing the output on the last n minutes of data? For example is ta.EMA(time_period=30) returning the EMA of the last half hour? If so, is there another keyword arg for days, mins, etc. or do we need to always use mins and make conversions as necessary?
Thanks,
David

2 responses

Hello David,

Quantopian have never mentioned built-in support for trailing stops as far as a I know. If someone were to add it to zipline (https://github.com/quantopian/zipline) there is chance it would be migrated to Quantopian as IB do support trailing stop orders.

The TA-Lib timeperiod is in the same timeframe as the backtest. Things change with the proposed 'history' feature (https://www.quantopian.com/posts/draft-proposal-of-new-data-history-api). In a minutely backtest you would be able to use TA-Lib functions on daily data:

def handle_data(context, data):  
    price_history = data.history(bar_count=30, frequency='1d', field='price')  
    macd_result = talib.MACD(price_history)  

P.

Peter,
Thanks for getting back to me, good to know IB supports trailing stops. I have been familiarizing myself with zipline and will check out how trailing stops might fit in. If the aim is to make everything available in live trading available in back tests it would be a useful addition. I look forwards to the history functionality, I like the direction it's heading.
David