Strategy Optimization Pass Number Function

There are two very useful purposes served by knowing the strategy optimization iteration or pass number during optimization:

  1. When outputting the results of optimization, as is commonly done when custom objective functions are being calculated and included with the optimization data, the header information for the data needs to be generated only on the first iteration or pass. Subsequent passes need only output the optimization data.

    Knowing the iteration or pass number allows the user to generate the header information during the first pass.
  2. Some calculations in a strategy may be time consuming and yet are not involved with parameters that are being varied by the optimization process. These calculations can be done on the first pass and stored in arrays.

    On all subsequent passes, the stored array values can be used, bypassing the need for performing the calculations repeatedly with each pass. In many cases, this will speed up the optimization process considerably.


The following should be observed when using this function:

  1. EL Collections for EasyLanguage must be installed for this function to work. A link is provided below for obtaining the code and documentation.
  2. The TempFile location defined in the variable definition as TempFile("E:/temp/temp.txt") may be modified by the user.

    Keep in mind that some versions of Windows prohibit the creation of files in protected directories, such as some areas of Drive C under Windows Vista or Windows 7. If you receive a "file can not be created" error message, it may be for this reason.
  3. Although FastFileAppend is generally faster than FileAppend, I have found it does not consistently create new files on my system. Therefore I have reverted to using FileAppend in this function.

The following code placed within your strategy may be used to call this function, which will return the optimization pass number:

vars: OptPassNr(0);

once begin

OptPassNr = _OptimizationPassNr;



Note the function needs to be called only once per strategy iteration and therefore is bracketed by once begin .... end statements.


Alternatively, the following variable definition will self-initialize at the start of each optimization run placing the optimization pass number in the variable OptPassNr:

vars: OptPassNr(_OptimizationPassNr);


In this case, no once begin .... end statement is needed and the function does not need to be explicitly called in the body of the strategy code.


Initial posted version: 03/31/10

Latest Update: 03/31/10

*.ELD files are compiled for TS 8.7

All ELD and code text files packaged here:


Users of earlier versions of Tradestation may compile the code
from the text files included in the above *.zip file.

The code and documentation for EL Collections for EasyLanguage may be visualized here:


The code may be visualized here:

Function OptimizationPassNr





Bookmark and Share