¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

order - close position by time condition


 

does it possible to create an order of closing position if some time passed?

I'm trying to create an order with 3 limits, take profit, stop loss, and time threshold. Let's say the order is "buy", if the price does up and hits some limit, take profit, if the price went down and hits some limit, stop loss and if nothing happens for a certain time, close the position.?

[I took it from? "advanced machine learning in finance" by Lopez]


Nick
 

¿ªÔÆÌåÓý

It seems like "good after time" would work for that.


On 12/16/2020 6:56 PM, refael.lasry@... wrote:

does it possible to create an order of closing position if some time passed?

I'm trying to create an order with 3 limits, take profit, stop loss, and time threshold. Let's say the order is "buy", if the price does up and hits some limit, take profit, if the price went down and hits some limit, stop loss and if nothing happens for a certain time, close the position.?

[I took it from? "advanced machine learning in finance" by Lopez]


 

Yes - create a parent order to enter the position, with 3 child orders to exit it: a take-profit order, a stop-loss order, and the timeout-exit order. All child orders should have the same OCAGroup so that one-cancels-all; the timeout order can be a regular sell/but @MKT order with a GoodAfterTime parameter that you can set to your required timeout so that it only gets active after the specified time.

As an alternative to using GoodAfterTime, some traders use a regular @MOC order (without a GoodAfterTime value), which only becomes active during the market close session (as dictated by the MOC mechanism).


 

thank you for your precise answer!
?
It took me quite some time to understands what did you mean. Also, GAT order doesn't work with brackets, I have no idea why.?


 

Does your GAT get rejected when you place the orders? In that case you might want to check your code again,

Just tried a bracket plus GAT and it placed without an error or warning (though markets are closed).




On Sat, Jul 24, 2021 at 04:06 PM, <refael.lasry@...> wrote:
thank you for your precise answer!
?
It took me quite some time to understands what did you mean. Also, GAT order doesn't work with brackets, I have no idea why.?


 

beautiful!
?
In this case, I conclude I might have a problem with my code.?
?
If it's possible from your side to share your code, I'll be thankful (totally understood if not).


 

my code (which not working):?
"original_order" is the brackets order (LMT + stop loss + take profit)


 

I don't do Python and my code heavily relies upon our Java framework. So it won't help you.

Looking at your code a few things come to mind:
  • the date is missing a colon between minute and second. It should be %H:%M:%S
  • there is no Time In Force called 'GAT' it should be 'GTC' (good until canceled)
  • I place all four orders into a single list with the three orders that make up the bracket order first and the GAT order last. The transmit flag is false for the first three and true for the last (GAT). All four orders are being placed together.
  • I do not manage the OCA group myself and let IB do that

On Sat, Jul 24, 2021 at 11:30 PM, <refael.lasry@...> wrote:
my code (which not working):?
"original_order" is the brackets order (LMT + stop loss + take profit)


 

ok, thank you very much! I'll go over it.