PDA

View Full Version : Infinite loop for a simple high frequency trading algorithm



425425425
03-13-2011, 03:56 PM
Hey guys, my VBA skills are very, very limited and i have this infinite loop in my codes right now:


If Sheets("Open Orders").Cells(1, 2) = "" Then
' The following loop submits the Buy section of bracket
Status = False
Do While Status = False
Status = api.AddOrder("ALGO", Range("Shares"), Range("MidMarket") - Range("Spread"), api.BUY, api.LMT)
Loop

At the moment I have to ctrl + break to unfreeze excel everytime i run the function, is there a quick and easy way to fix this?

The RIT software returns a string called “TRUE” or “FALSE” when I submit a trade request. If the
order is successful, it returns “TRUE”, otherwise it returns “FALSE”. By setting the “Status” variable as
false, and then running the addorder command, you can track when it properly submits the order. The
program doesn’t exit the loop (and keeps trying to submit the order) until it is successful.

a million thank-you's ..

CharlesH
03-13-2011, 05:00 PM
HI,

Welcome to the forum.
In your code you set "Status" to false and then within the loop you have "Status" = something. I'm not sure, but within the loop you should have something other than "Status" = something. Being you are wanting to exit the loop if "Status" becomes true. So try to change "Status" within the loop to something else.