Back to Community
Algo wont let go of position

Hi all,

In my journey of learning, I have been slowly building on a single Algo. I am currently experience an issue that I cannot wrap my head around. The algo performs ok, filter for penny stocks, but in July 2017 I catch the up spike of PRPO. This is no a bad thing but as I am using SMAs I essentially hold onto the stock and watch it loose value as it dilutes. My PRPO position should sell immediately after the spike as it is no longer in my pipeline_results. But it doesn't. What I am missing?

Clone Algorithm
4
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 59f1ff6657cfe644d9fa0065
There was a runtime error.
2 responses

Hello Michael,

Seems like your algorithm won't let go of PRPO position, because of following line in code:

and stock not in context.stocks_sold:  

I removed that part of the code and PRPO position will get sold on 2017-07-06 for unit price of $15.40 and then it won't be in list of stocks in 2017-07-07.

Clone Algorithm
0
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 59f376ccc163794458a7b80b
There was a runtime error.

Hi Mikko,

ah, I looked back and it seams that it tried a sell order, but was not filled, and I close all open orders 10 min before market close. So it was added to context.stocks_sold. I guess I will have to also amend within my canOpenOrders function.

Thanks!