asynchronous order processing? (futures with PRT+IBRK)

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #266568 quote
    justisanjustisan
    Participant
    Senior

    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

    GraHal thanked this post
    #266569 quote
    GraHalGraHal
    Participant
    Legend

    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.

    #266570 quote
    justisanjustisan
    Participant
    Senior

    sure I tried, your “should” is the keyword, does not work, leads to exactly same issue as my mentioned options…

    #266571 quote
    GraHalGraHal
    Participant
    Legend

    Are your pending orders created within the same If Condition under which the Buy order was created?

    #266572 quote
    justisanjustisan
    Participant
    Senior

    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.

    #266573 quote
    GraHalGraHal
    Participant
    Legend

    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?


    #266574 quote
    GraHalGraHal
    Participant
    Legend

    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.

    #266575 quote
    justisanjustisan
    Participant
    Senior

    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.

    #266576 quote
    JSJS
    Participant
    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…

    #266577 quote
    justisanjustisan
    Participant
    Senior

    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”.

    #266578 quote
    JSJS
    Participant
    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…

    #266579 quote
    justisanjustisan
    Participant
    Senior

    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…

    #266580 quote
    JSJS
    Participant
    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…

    #266581 quote
    GraHalGraHal
    Participant
    Legend

    How about trying:

    SET STOP PLOSS XX
    SET TARGET PPROFIT YY
    

    #266582 quote
    JSJS
    Participant
    Master

    Exactly, GraHal, those are the orders that are linked to the open position…

    GraHal thanked this post
Viewing 15 posts - 1 through 15 (of 23 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

From idea to ProBuilder code in seconds.

Your coding copilot for ProRealTime™. Ask in plain English — get clean, ready-to-paste indicators, screeners and systems.

Available in 7 languages
Try ProRealAI

asynchronous order processing? (futures with PRT+IBRK)


Platform Support: Charts, Data & Broker Setup

New Reply
Author
author-avatar
justisan @justisan Participant
Summary

This topic contains 22 replies,
has 4 voices, and was last updated by GraHalGraHal
7 hours, 32 minutes ago.

Topic Details
Forum: Platform Support: Charts, Data & Broker Setup
Language: English
Started: 11/27/2026
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...