WAITDLL

Discuss, post your questions about TWSLink here.

Users who just registered, please write an email to
forum@trade-commander.de
with your username mentioned.
So we can distinguish you from bots.
Thank you
Post Reply
sectorbets
Posts: 92
Joined: Wed Apr 26, 2017 12:41 pm

WAITDLL

Post by sectorbets »

Could you tell me how it works ?? Does everything stop, or does the TradeStation code keep running until it comes to the next DLL function ?? Is this in effect a pause ?? What happens if multiple cores are running??

Thank you
Rick

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: WAITDLL

Post by board_admin »

The calling thread is suspended, goes into idle state.
So the calling script stops. If another script runs in the same thread, this stops as well.

sectorbets
Posts: 92
Joined: Wed Apr 26, 2017 12:41 pm

Re: WAITDLL

Post by sectorbets »

Thank you -- are there any nuances such as the computer still has the proper time and the market data is all there and the DLL will pick up where it left off talking to IB??

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: WAITDLL

Post by board_admin »

The time will be proper etc. It just sets the thread to idle. The script pauses script execution the denoted time at this point.
Thats all.

I have no TradeStation and also do not use MultiCharts this time so i can't make a definite statements how WAITDLL
exactly affects your script. But i guess, when you call WAITDLL(x), then the script can't get called for x milliseconds,
even if you had 1000 ticks in the meantime.

Let's say there were 10 ticks during the WAITDLL, then, i guess, the script is called 10 times in a row after WAITDLL
returned and the current script run completed.

(The other possibility is that TS just skips those ticks).

It is the question what do you like to accomplish with WAITDLL.

The typical purpose would be to wait until an order been filled. But this means also that the script is blocked
until the condition is full filled.

If your script depends on an order being filled, you may drive better with a conditional route, depending on an order
been filled or not.

As is said: The WAITDLL blocks or idles the calling thread. If multiple scripts reside in the same thread, you may
need to change your design.

I think it is simple to figure this out: Write some simple scrips with WAITDLL calls and without and attach them to multiple
charts. Check what happens with the script without WAITDLL calls when WAITDLL called in another script and so on.

sectorbets
Posts: 92
Joined: Wed Apr 26, 2017 12:41 pm

Re: WAITDLL

Post by sectorbets »

Yes, we want to wait until an order is filled -- we have tried using wait_for_filled with many different times and it works most of the time, but some times it times out even at 20 seconds!! We have also tried get_acc_val to be sure there is enough BP -- this almost always goes into an infinite loop, so I guess we don't understand how it works.

Our issue is simple -- we sometimes want to reverse a position from long to short or short to long and if there isn't enough BP available at at IB, the trade is rejected, so we have to find a reliable way to close the open position and wait for IB to report back before placing the new order. There is enough BP 100% of the time once the open order is filled -- we just have to find a way to verify that it is filled and the BP is available

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: WAITDLL

Post by board_admin »

WAIT_FOR_FILLED should be good for this. It breaks when an order been rejected.

It returns 1, when filled. 0 when timeout. -2 when order rejected or cancelled, -1 when initial or inactive (can't reach filled state).


Are you sure you get a timeout when you place a reverse order which violates margin ?

sectorbets
Posts: 92
Joined: Wed Apr 26, 2017 12:41 pm

Re: WAITDLL

Post by sectorbets »

I didn't describe the situation well enough. The wait_for_filled works fine, but sometimes IB has not reported back the BP even though it has reported back a fill, so when the next order is placed, there isn't enough BP and the order is rejected.

Here is our code: -- it may be complicated since we are running in an FA environment with about 50 sub accounts

If MP = -1 then begin
oidCloseOrderVXX = PLACE_ORDER(uidVXX,0,"BUY","MKT",LastVXX,0,0.0,"DAY",-1,0);
setFAVXX = SET_FA_MEMBERS(oidCloseOrderVXX,"","","SVXY Algo Alloc","","",1);

statusVXX = WAIT_FOR_FILLED(oidCloseOrderVXX,2000);
end;

uidOfOrderVXX=PLACE_ORDER(uidVXX,0,"BUY","MKT",PosSizeVXXX,0,0.0,"DAY",-1,0);
SetOrderVal14 = SET_ORDER_VAL(uidOfOrderVXX,14,"0",-1);
SetOrderVal67 = SET_ORDER_VAL(uidOfOrderVXX,67,"Adaptive",-1);
SetOrderVal68 = SET_ORDER_VAL(uidOfOrderVXX,68,"adaptivePriority=Normal",-1);
setFAVXX = SET_FA_MEMBERS(uidOfOrderVXX,"","","SVXY Algo Alloc","","",1);

Post Reply