Page 1 of 1


Posted: Wed May 02, 2018 7:45 pm
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


Posted: Wed May 02, 2018 8:02 pm
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.


Posted: Wed May 02, 2018 8:27 pm
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??


Posted: Wed May 02, 2018 10:49 pm
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.


Posted: Thu May 03, 2018 11:47 am
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


Posted: Thu May 03, 2018 12:10 pm
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 ?


Posted: Thu May 03, 2018 12:37 pm
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);

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);