The Timer Object can be used to delay the execution of EasyLanguage code. This may be useful when issuing orders from a strategy to ensure each order is received by the trade server and acknowledged before proceeding to the next step. Failure to do so can create out-of-sync conditions with strategies that use OrderTickets to generate or cancel orders, or when restarting the strategy to re-sync the real-world position and strategy position.
The following example of code shows how a series of code steps within a strategy or indicator may be delayed a user-specified number of seconds by reusing a single Timer Object:

Running this code as a strategy produces the following print log:

Line 26
Timer1.AutoReset must be set to false to prevent the timer from firing more than once per step.
Lines 32-45
Method Step1() contains the first segment of code to be executed at the beginning of a series of delayed code segments.
Timer1.Elapsed += Step2; assigns method Step2 as the next step to be executed when the timer elapses.
The notation += actually adds method Step2 to the list of methods that will all fire when the timer elapses.
Because Timer1.Elapsed is pointing to a list of methods, rather than a single method, subsequent re-use of the same timer object to point to the method to execute in the next step will require removing Step2 from the existing list, before adding the new method to be executed.
Lines 57-58
In Method Step2(), the notation "-=" removes the previously assigned method Step2() from the list of methods that the timer object will trigger when it expires, and the notation "+=" adds the new Method Step3() to the list of methods that will be executed when the timer is re-started and then expires.
Print Log
Fourth column shows computer time to the nearest second, verifying the delay between each code segment is the number of seconds specified in the input parameters.
Downloads
Initially posted version: 01/16/14
Latest Update: 01/16/14
*.ELD files are compiled for TS 9.1
Users of earlier versions of TradeStation may compile the code from the text files included in the above *.zip file.
The code may be visualized here:
