Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Problem with orders, and resample ?

This algorithm seems to just keep on taking trades even tho I have tried to set up certain criteria in order to stop it from doing this.

This is a test algorithm with a simple sma signal for when to buy, when an order is taken, a SL and TP is saved in context.l and context s.
if price reaches current price when trade was taken + context.tp then i would like the algorithm to close all open positions, and the opposite for SL.
It is worth mentioning that I would not like a new position besides termination of orders when one is open.

However what seems to happen is an aggregation of both short and long position to a high degree.

  • How is this possible with the logicks that are in place ? If initialize is only run once, i cannot quite see how i get the bypass.

  • I also thought that : if es_primary not in open_orders: would stop it from having more than one position

When i look at the order history they do not follow 15 minutes intervals so there is also something that i do not get with the resampling method.

Hope any one can help me with one or more of these issues.