Dear Nicolas and PRC-team,
maybe you would be able to clarify with PRT technical team below issue which I face permanently since I ever started trading futures (PRT+IBRK account) few years. long strategy opens a position (on the short side it’s same issue), let’s say 1 lot, with stoploss and takeprofit levels set by commands “set stop price…” and “set target price…”. if non of them are hit by set time hhmmss position has to be liquidated by that time “at market”. I tried 2 options for the time-dependent liquidation:
a:
defparam flatafter = hhmmss
and also alternatively:
b:
if time = hhmmss then
set stop price 0
set target price 0
sell at market
endif
yet both lead to the same issue: according order history the pending takeprofit order triggers a margin request, broker “figures out” that there is not enough capital on the account, as a consequence takeprofit order gets rejected and my system gets deactivated (positions gets liquidated and stoploss order gets cancelled as intended). I mean: obviously for the broker it looks like I would like to obtain a second lot at the time hhmmss, while in fact instruction in code is very clear: at the instructed time pending stoploss & takeprofit orders have to be cancelled and open position to be sold at market. logically I can only conclude that this order process at the side of PRT and/or IBRK runs with no or with wrong synchronization and therefore triggers unnecessary margin request. could you investigate on that? and in particular clarify following:
1. OCO linkage: can you confirm whether stoploss and takeprofit orders are still handled as separate, independent orders at the broker in automated trading?
2. order cancellation sequence: when a position is closed by “at market” instruction are the stoploss and takeprofit orders cancelled with the broker first? does proorder wait for confirmation of both cancellations before submitting the market order?
3. margin rejection: why is the still-pending takeprofit limit order rejected due to insufficient margin after the market closing order has been executed, instead of being cancelled normally?
4. how to avoid that obsolete margin request?
thanks a lot and cheers
justisan
Did you try:
if time >= hhmmss then
sell at market
endif
The Pending Orders linked to the closed trade should disappear at the same time as the trade is closed.
sure I tried, your “should” is the keyword, does not work, leads to exactly same issue as my mentioned options…
Are your pending orders created within the same If Condition under which the Buy order was created?
tried within, tried outside, result/issue is same: pending takeprofit limit order (does not matter if on long-strategy or on short-strategy) is triggering margin requests, gets rejected and this triggers deactivation of the algo. the only “solution” so far is to keep more than double margin on the account, but that must not be the solution.
I guess you know, IBKR ‘ringfences’ margin when you place orders?
- Impact on Buying Power vs. Maintenance Margin. While a pending order sits open on the book, it does not incur financing charges or count toward your Maintenance Margin (meaning an unfilled order will not trigger a liquidation). However, IBKR’s risk engine factors open orders into your Available Funds and Buying Power calculations so you cannot accidentally over-leverage your account across dozens of simultaneous pending orders.
Is above of any help? Or is it that your pending orders are not getting cancelled?
With IG, this is what happens (no ringfencing of margin):
Execution Risk. Because funds are not ring-fenced for pending orders, you can place multiple working orders that exceed your total account balance. However, when the market reaches your trigger price, IG checks your available margin again. If your free margin has dropped below the required amount due to losses on other open trades, the pending order will be rejected rather than filled.
I am afraid it’s not a help. I know what has to happen: if and when open position is instructed to be liquidated “at market” all other orders for the same position have to be cancelled: at the same time, or before position is liquidated. in reality with a difference of few milliseconds (according order protocol ) it is processed in not the right sequence and the takeprofit limit order instead of being simply cancelled triggers margin request – as if I would be intending to increase the position instead of liquidating the open one.
JSParticipant
Master
justisan, I suspect the problem lies in the use of SET STOP PRICE and SET TARGET PRICE orders…
These are pending orders that are independent of the original entry order and are not directly linked to the entry price or the position itself…
Consequently, at the moment of liquidation, there are potentially three separate orders in the market:
- One Sell Market order to close the existing position.
- One pending stop-loss order.
- One pending take-profit order.
If the position is closed first, the two pending orders may remain active at the broker, still reserving margin independently (potentially twice the required margin)…
If there is insufficient available margin, IBKR may then reject one or both pending orders, resulting in the ProOrder system being deactivated…
I suspect this is the underlying cause of the problem…
if I use “sell at xxx limit” and “sell at yyy stop” instead of set stop / set target, the same issue appears. so it’s not about what kind of way I take to define stoploss and takeprofit, it’s about how PRT/IBRK processes the instructions. therefore I am asking Nicolas&co 😀
btw as I a mentioned, in order protocol visible wrong overlapping of processing sequence is ultrashort – just 2 milliseconds (case which I had yesterday) after selling the position at market the still pending limit order linked to that liquidated position gets a rejection “due to insufficient margin”.
JSParticipant
Master
That’s because limit and stop orders are also pending orders that are not linked to the original entry order or the position itself…
So, when closing the position, you still have three separate orders in the market: one market order to close the position and two independent pending orders (stop-loss and take-profit)…
It’s exactly the same situation…
theoretically stoploss and takeprofit are linked to the open position (see probuilder documentation). but I am afraid/suspecting they are “linked” only on PRT side, not on IBRK. and that is “wrong”, leading to wrong processing sequence, triggers an obsolete margins request. which makes me a bit mad 😀 since years…
JSParticipant
Master
Correct. According to the ProBuilder documentation, stop-loss and take-profit orders are linked to the open position…
However, those are not the orders you are using…
Instead, you are using SET STOP PRICE, SET TARGET PRICE, and separate limit and stop orders…
These orders are not linked to the original entry price or the position itself…
Consequently, when you close the position at market, you still have three separate orders in the market: one market order to close the position and two independent pending orders (stop-loss and take-profit)…
That’s the fundamental difference, and potentially the source of the problem…
How about trying:
SET STOP PLOSS XX
SET TARGET PPROFIT YY
JSParticipant
Master
Exactly, GraHal, those are the orders that are linked to the open position…