I saw in the documentation that trailing stop orders are to come.
Any help with code (python) that could monitor 1 minute price moves and create a market sell order when the ‘trailing stop’ has been reached?
Buy SPY @ $300
Currently, I could open a limit sell at $270 (down 10%).
If SPY runs to $350, I’d like to have code that is checking every minute if SPY falls below $315 (down 10% from $350). Once the current price hits $315, I’d automatically enter a market sell order.
I’m learning python, so my rough logic would be:
executed_order_price = [get from orders]
current_price = [get from market]
if(current_price > executed_order_price):
if current_price < (high_price * 0.9)
Ok, here’s how I’m implementing. I think this essentially gets me there:
current_position_price = api.polygon.last_trade(ticker).price
barset = api.get_barset(ticker,‘minute’,)
ticker_bars = barset[ticker]
price_1m_ago = ticker_bars[-2].c
if current_position_price < price_1m_ago:
My algo runs ~ every minute, so it will update with the last trade and compare to the last completed minute. If a stock is rising, the current_position_price will be greater than the previous minute. At the next refresh, the price_1m_ago will then be higher, and ‘trail’ the current price on its way up.
Trailing Stop - Beta Program
Finally, we are ready for a Beta program for the Trailing Stop. Please see the draft document here.
As of today, we plan to spend a couple of weeks doing a beta test for the Trailing Stop until the full launch. We are looking for 20-30 beta users for Trailing Stop.
If you are interested in this, please fill out your information in this google form so that we can invite you to the private Slack channel.