Moving stops w/QScript

Have a QScript to share, or need help with programming? Post your comment here.
Post Reply
sbank
Posts: 174
Joined: Tue Jul 21, 2015 9:35 pm
Contact:

Moving stops w/QScript

Post by sbank » Sun Aug 05, 2018 12:50 am

Is there a mechanism to move an already existing stop w/QScript from an IB perspective?

For example, if I have something like this:

Code: Select all

                
ref2=IB_PlaceOrder("sell",contracts,stop,"stop","gtc",myoco);

And the price action is moving in my favor. I would like to either tighten my stop, or do a trailing stop. I looked through all the "IB_" commands, and I see nothing that takes a reference and then modifies it with a new value.


I could probably just cancel the order, then create a new one. But it gets a bit messy since I have also a target limit order set as part of an OCO group. So I would have to cancel all, then re-build both. And if I want to do this on every bar, just seems a bit wasteful...

User avatar
earik
Site Admin
Posts: 474
Joined: Mon Dec 01, 2014 12:41 pm
Contact:

Re: Moving stops w/QScript

Post by earik » Mon Aug 06, 2018 6:32 pm

Hi sbank,

Yeah, you have to cancel-replace it. IB doesn't make it easy with OCO groups, so you have to cancel-replace the entire thing, not just the one order. If your target and stops are far apart, and there's no chance they would be hit on the same bar, you could always just check for when you go flat, and then cancel the target at that time. That way you'd preserve your place in the queue, and wouldn't always reset yourself to the end each time you had to move your stop. If you really want to get fancy with that idea, you could do entries on a regular chart, and then do stop management and cancelling on a 1min chart that just floats in the background and does housekeeping tasks. More complicated, but if keeping your position in the limit queue is important, it might be an option to consider...

Earik

sbank
Posts: 174
Joined: Tue Jul 21, 2015 9:35 pm
Contact:

Re: Moving stops w/QScript

Post by sbank » Wed Aug 08, 2018 2:09 pm

IB doesn't make it easy with OCO groups, so you have to cancel-replace the entire thing
Side question, how does this work via modifying the order off the chart? I can just doubleclick the order and change number of contracts, limit/stop price, etc. It works quite nicely from this interface.

I was hoping that the interface was just no exposed via qscript. But your initial comment makes it sound like this is more of an IB API problem.

User avatar
earik
Site Admin
Posts: 474
Joined: Mon Dec 01, 2014 12:41 pm
Contact:

Re: Moving stops w/QScript

Post by earik » Wed Aug 08, 2018 6:45 pm

I had issues implementing the cancel-replace in IB properly (there was an issue in the API back then about it), so it is done on W59's end with multiple calls rather than just one. It all works perfectly well that way, but does require a bit more communication than you might expect just from using it. So if you are doing to do a similar thing in QScript, you'll need to jump through extra hoops, and that's why there isn't a direct interface to their own cancel-replace in QScript.

Earik

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests