Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (degenerate_762), 1,098 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
IB - Stop order for options #482241
01/15/21 10:59
01/15/21 10:59
Joined: Sep 2020
Posts: 2
A
Average Offline OP
Guest
Average  Offline OP
Guest
A

Joined: Sep 2020
Posts: 2
Hey,
I am using IB and trying to send a stop order with my market order, but have had no success so far, is it not implemented for options or am I doing something wrong?
Options are even explicitly referenced in the remarks of "TradeMode" and "Stop", which is why I think it should be supported.


I followed the instructions in the IB / TWS Bridge (https://manual.zorro-project.com/ib.htm):
"Set TR_ENTRYSTOP for adding a stop order to a trade; this is for special purposes only since the stop order is not managed by Zorro either,..."

- TR_ENTRYSTOP: "Enter any trade with an additional stop order at distance Stop*StopFactor on NFA accounts, if supported by the broker API (see remarks). "
"So use this command in special cases only, for instance with option contracts or when Zorro does not control the trade."
(https://zorro-project.com/manual/en/trademode.htm)

- Stop: "For options the prices are always distances, f.i. Stop = 0.7 * contractPrice(ThisContract) sets a stop limit at 70% loss."
- StopFactor: "At 0 the stop is only controlled by software; at 1 it is only controlled by the broker."
(https://zorro-project.com/manual/en/stop.htm)

- SET_ORDERTYPE 2 - GTC (good-till-cancelled); order stays open until completely filled
+8 - STOP; add a stop order at distance Stop*StopFactor on NFA accounts (see remarks).
(https://zorro-project.com/manual/en/brokercommand.htm)


Code
setf(TradeMode,TR_ENTRYSTOP);			//also tried setf(TradeMode,TR_ENTRYSTOP|TR_GTC);
brokerCommand(SET_ORDERTYPE,8);			//with brokerCommand(SET_ORDERTYPE,2+8);

Lots = 1;
StopFactor = 1;
Stop = 0.1 * contractPrice(ThisContract);	//Stop limit at 10% loss

ThisTrade = enterLong(TMF_check_exit_conditions); 


I have also tried every combination and sequence I can think of, but I can't get anywhere.

The only thing that happens is that an MKT order is sent with 1Day expiration (no matter if GTC is selected or not, but I believe the GTC is more on Zorro's side and not meant for IB).
If I also add an OrderLimit, when I buy I get a message from Zorro that 0%@ContractAsk was bought, do I get the message because the purchase was not completed on IBs site and only the order was sent to IB? Because normally for the 0% the Lots*Multiplier should be displayed, so it says 100@ContractAsk.


PS
I have also tried to send an order using the brokerCommand(SET_ORDERTEXT ,"STP/"), but the problem is that I cannot send an additional stop value.
(http://interactivebrokers.github.io/tws-api/basic_orders.html)

Re: IB - Stop order for options [Re: Average] #482244
01/16/21 12:45
01/16/21 12:45
Joined: Apr 2008
Posts: 585
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 585
Austria
The TMF is probably not useful, you cannot check exit conditions of a stop order because its in fact 2 orders. The rest looks ok, but I dont know if stop orders work with options at all. Maybe IB support can tell that. 0% means that 0% of that order was filled, it was probably a GTC order.

Re: IB - Stop order for options [Re: Petra] #482261
01/18/21 15:16
01/18/21 15:16
Joined: Sep 2020
Posts: 2
A
Average Offline OP
Guest
Average  Offline OP
Guest
A

Joined: Sep 2020
Posts: 2
IB does support stop orders for options. (https://www1.interactivebrokers.com/en/index.php?f=609)
Zorro seems to offer stop orders for options for at least one broker as well, otherwise it probably wouldn't be mentioned everywhere, the question is if Zorro also supports it for IB and I just can't get it to work.


Your comment regarding my TMF raised a few more questions though:

1. Assuming the stop order would work, how do I even manage this additional order with Zorro.
There is a brokerCommand "DO_CANCEL" in the new beta to close open orders, but I assume this only works for partial fills of the same TradeID, but here it should theoretically be a different TradeID, since it is a different trade in the opposite direction, or is it a bracket order with the same ID (https://interactivebrokers.github.io/tws-api/bracket_order.html)?

2. Do I also get open orders with GET_TRADES or only trades? So if I have multiple orders open for an asset (e.g. because of limit or stop orders), do I get the TradeID's and then how can I find out if they are trades yet or still orders? (maybe using Lot differences?)

3. If I bought an option via enterLong(TMF) and use a TMF on a tick basis, will the TMF be updated based on the ticks of the underlying (i.e. stock prices) or with new price information of the option?


Sorry for all my questions, working with Zorro regarding backtesting, optimizing etc. was a lot clearer and easier (probably because there was no BrokerAPI involved), but since I want to get my scripts running live as well, I still lack a bit of understanding how some things are implemented.

Re: IB - Stop order for options [Re: Average] #482263
01/19/21 10:52
01/19/21 10:52
Joined: Apr 2008
Posts: 585
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 585
Austria
DO_CANCEL cancels the open order, but I dont know if the IB API then also cancels the connected stop order. I have not yet had that case. Maybe IB support can tell that. GET_TRADES gets trades, not orders. I know the TMF will run on any incoming underlying price, even when the options price has not changed.


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1