Hi community,

I am new here, so sorry for the dumb question. I am trying to wrap me head around the different type of orders and how to manage them.

I am backtesting on a daily frequency, so on day X-1 I find a good setup and I want to trade on day X, then I submit a StopMarketOrder within the on_data block on day X-1, so that as soon as the price hit the mark on day X, it trigger the MarketOrder that gets filled ASAP. This works fine as expected, but the problem is about TP (take profit) and - mainly - about SL (stop loss), which is my biggest concern.

 

If I submit the SL StopMarketOrder at the same time on Day X-1, sometimes it got hit before the other order takes place, so I enter in a short positon that I have no intention to have.

I tried to submit it based on the even on order, so when my actual order get filled, but it get delayed and actioned the day X+1, which is too late and I took the fall already.

So, is it there a way to submit both, but only have it if the first one is actually filled (or partially filled)?

Thanks for your advices in advance. Michele